CalcolaPI




Function CHKIVA(Piva As String, N As Integer) As String
Dim IV, UF As String

If Not Piva Like "###########" Then
MsgBox ("Il numero dei caratteri della Partita IVA" & _
Chr(13) & "non corrisponde (devono essere 11 caratteri)")
CHKIVA = ""
Exit Function
End If

'Verifica ultima cifra

Dim i As Integer, SumDisp As Integer, SumPari As Integer, _
Radd As Integer, SumTot As Integer, Check As Integer

'1.Si sommano le cifre di ordine dispari (1,3,5,7,9)

For i = 1 To 9 Step 2
SumDisp = SumDisp + Val(Mid(Piva, i, 1))
Next i

'2.Si raddoppiano le cifre di ordine pari (2,4,6,8,10)

'se il risultat e' un numero di due cifre, si riduce ad una

'sola cifra sommando le due che lo compongono (es: 15 diventa

'6: 1+5)


For i = 2 To 10 Step 2
Radd = 2 * Val(Mid(Piva, i, 1))
If Radd > 9 Then
Radd = Val(Left(CStr(Radd), 1)) + Val(Right(CStr(Radd), 1))
End If
SumPari = SumPari + Radd
Next i

'3. si sommano tutti i precedenti risultati (delle cifre

'dispari e di quelle pari raddoppiate.

'4. si determina il totale delle due somme

SumTot = SumPari + SumDisp
'5.del risultato, si prende solo la cifra delle unita'

SumTot = SumTot Mod 10
'6.Questa cifra si sottrae dal numero 10

Check = (10 - SumTot) Mod 10

UF = ""
IV = Mid(Piva, 8, 3)
If IV = "001" Then UF = "Torino"
If IV = "002" Then UF = "Vercelli"
If IV = "003" Then UF = "Novara"
If IV = "004" Then UF = "Cuneo"
If IV = "005" Then UF = "Asti"
If IV = "006" Then UF = "Alessandria"
If IV = "007" Then UF = "Aosta"
If IV = "008" Then UF = "Imperia"
If IV = "009" Then UF = "Savona"
If IV = "010" Then UF = "Genova 1"
If IV = "011" Then UF = "La Spezia"
If IV = "012" Then UF = "Varese"
If IV = "013" Then UF = "Como"
If IV = "014" Then UF = "Sondrio"
If IV = "015" Then UF = "Milano 1"
If IV = "016" Then UF = "Bergamo"
If IV = "017" Then UF = "Brescia 1"
If IV = "018" Then UF = "Pavia"
If IV = "019" Then UF = "Cremona"
If IV = "020" Then UF = "Mantova"
If IV = "021" Then UF = "Bolzano"
If IV = "022" Then UF = "Trento"
If IV = "023" Then UF = "Verona"
If IV = "024" Then UF = "Vicenza"
If IV = "025" Then UF = "Belluno"
If IV = "026" Then UF = "Treviso"
If IV = "027" Then UF = "Venezia"
If IV = "028" Then UF = "Padova"
If IV = "029" Then UF = "Rovigo"
If IV = "030" Then UF = "Udine"
If IV = "031" Then UF = "Gorizia"
If IV = "032" Then UF = "Trieste"
If IV = "033" Then UF = "Piacenza"
If IV = "034" Then UF = "Parma"
If IV = "035" Then UF = "Reggio Emilia"
If IV = "036" Then UF = "Modena"
If IV = "037" Then UF = "Bologna 1"
If IV = "038" Then UF = "Ferrara"
If IV = "039" Then UF = "Ravenna"
If IV = "040" Then UF = "Forli'"
If IV = "041" Then UF = "Pesaro"
If IV = "042" Then UF = "Ancona"
If IV = "043" Then UF = "Macerata"
If IV = "044" Then UF = "Ascoli Piceno"
If IV = "045" Then UF = "Massa Carrara"
If IV = "046" Then UF = "Lucca"
If IV = "047" Then UF = "Pistoia"
If IV = "048" Then UF = "Firenze 1"
If IV = "049" Then UF = "Livorno"
If IV = "050" Then UF = "Pisa"
If IV = "051" Then UF = "Arezzo"
If IV = "052" Then UF = "Siena"
If IV = "053" Then UF = "Grosseto"
If IV = "054" Then UF = "Perugia"
If IV = "055" Then UF = "Terni"
If IV = "056" Then UF = "Viterbo"
If IV = "057" Then UF = "Rieti"
If IV = "058" Then UF = "Roma 1"
If IV = "059" Then UF = "Latina"
If IV = "060" Then UF = "Frosinone"
If IV = "061" Then UF = "Caserta"
If IV = "062" Then UF = "Benevento"
If IV = "0e'" Then UF = "Napoli 1"
If IV = "064" Then UF = "Avellino"
If IV = "065" Then UF = "Salerno"
If IV = "066" Then UF = "L'Aquila"
If IV = "067" Then UF = "Teramo"
If IV = "068" Then UF = "Pescara"
If IV = "069" Then UF = "Chieti"
If IV = "070" Then UF = "Campobasso"
If IV = "071" Then UF = "Foggia"
If IV = "072" Then UF = "Bari"
If IV = "073" Then UF = "Taranto"
If IV = "074" Then UF = "Brindisi"
If IV = "075" Then UF = "Lecce"
If IV = "076" Then UF = "Potenza"
If IV = "077" Then UF = "Matera"
If IV = "078" Then UF = "Cosenza"
If IV = "079" Then UF = "Catanzaro"
If IV = "080" Then UF = "Reggio Calabria"
If IV = "081" Then UF = "Trapani"
If IV = "082" Then UF = "Palermo"
If IV = "083" Then UF = "Messina"
If IV = "084" Then UF = "Agrigento"
If IV = "085" Then UF = "Caltanissetta"
If IV = "086" Then UF = "Enna"
If IV = "087" Then UF = "Catania"
If IV = "088" Then UF = "Ragusa"
If IV = "089" Then UF = "Siracusa"
If IV = "090" Then UF = "Sassari"
If IV = "091" Then UF = "Nuoro"
If IV = "092" Then UF = "Cagliari"
If IV = "093" Then UF = "Pordenone"
If IV = "094" Then UF = "Isernia"
If IV = "095" Then UF = "Oristano"
If IV = "096" Then UF = "Monza (Milano 2)"
If IV = "097" Then UF = "Prato (Firenze 2)"
If IV = "098" Then UF = "Brescia 2"
If IV = "099" Then UF = "Chiavari (Genova 2)"
If IV = "100" Then UF = "Roma 2"
If IV = "101" Then UF = "Bologna 2"
If IV = "102" Then UF = "Napoli 2"


If Check = Val(Right(Piva, 1)) And N = 0 Then CHKIVA = "Esatto"
If Check <> Val(Right(Piva, 1)) And N = 0 Then CHKIVA = "Sbagliato"

If Check = Val(Right(Piva, 1)) And N = 1 Then CHKIVA = ""
If Check <> Val(Right(Piva, 1)) And N = 1 Then MsgBox ("La partita I.V.A. e' sbagliata." & Chr(13) & "L'ultimo carattere dovrebbe essere: " & Check): CHKIVA = ""

If Check = Val(Right(Piva, 1)) And N = 2 Then MsgBox ("La partita I.V.A. e' esatta ed e' stata" & Chr(13) & "rilasciata dall'ufficio di: " & UF & "."): CHKIVA = ""
If Check <> Val(Right(Piva, 1)) And N = 2 Then MsgBox ("La partita I.V.A. e' sbagliata." & Chr(13) & "L'ultimo carattere dovrebbe essere: " & Check): CHKIVA = ""



End Function










( calcolapi.html )- by Paolo Puglisi - Modifica del 17/12/2023