Salve, sono nuovo del forum,
Non so se questo post è già presente nel forum, chiedo scusa in anticipo.
Espongo brevemente il mio problema,
ho trovato su internet alcune soluzioni al mio problema, ma purtroppo non funzionano correttamente.
in un report ho due campi uno denominato IMPMO e l'altro è un campo da una queri che viene fuori da una funzione che posto in calce:
Quando nel repor leggo nel campo IMPMO il valore 1.577,80 il campo della funzione mi riporta millecinquecentosettantasette/77
non so dive è l'errore.
ribadisco che questa funzione l'ho trovata su un forum.
Ciao a tutti e grazie a chi può darmi un aiuto.
Function NumeriPerLettere(VALORE) As String
VALORE = Replace(VALORE, ".", "")
Dim Sez()
Unita = ""
Decine = ""
Centinaia = ""
Uni = ""
Dec = ""
Cent = ""
Sezioni = ""
NoUnits = 0
'Ritorna se vi è; la virgola
numInt = InStr(VALORE, ",")
numDecim = Len(VALORE) - InStr(VALORE, ",") 'Controlla il numero dei decimali dopo la virgola
'Controlla se il numero è; privo di virgola
If numInt = 0 Then
VALORE = Left(VALORE, Len(VALORE))
'Mette come decimali due zeri
decimali = "00"
ElseIf numDecim = 1 Then 'Se c'è; un solo decimale dopo la virgola gli aggiunge uno zero
VALORE = Left(VALORE, Len(VALORE) - Len(Mid(VALORE, (InStr(VALORE, ",")))))
decimali = Right(VALORE, 1) & "0"
Else
VALORE = Left(VALORE, Len(VALORE) - Len(Mid(VALORE, (InStr(VALORE, ",")))))
'Mi restituisce i due decimali alla destra della virgola
decimali = Right(VALORE, 2)
End If
Cifre = Len(VALORE)
Stringa = ""
P = 0
For Posizione = 1 To Cifre
P = P + 1
Stringa = Mid(VALORE, Cifre - (Posizione - 1), 1) & Stringa
If P = 3 Then
Stringa = "\" & Stringa: P = 0
End If
Next
If Left(Stringa, 1) = "\" Then Stringa = Mid(Stringa, 2, Len(Stringa))
Sezioni = Empty
Sezioni = Split(Stringa, "\")
Nsez = UBound(Sezioni) + 1
Erase Sez()
ReDim Sez(Nsez)
For S = 0 To Nsez - 1
If Len(Sezioni(S)) < 3 Then Sezioni(S) = String(3 - Len(Sezioni(S)), "0") & Sezioni(S)
If Len(Sezioni(S)) = 3 Then
Centinaia = Mid(Sezioni(S), 1, 1)
Select Case Centinaia
Case "0"
Cent = ""
Case "1"
Cent = "cento"
Case Else
Cent = Converti(Centinaia) & "cento"
End Select
Decine = Mid(Sezioni(S), 2, 1)
Select Case Decine
Case "0"
Dec = ""
NoUnits = 0
Case "1"
Dec = Converti(Decine & Mid(Sezioni(S), 3, 1))
NoUnits = 1
Unita = ""
Case Else
Dec = Converti(Decine & "0")
NoUnits = 0
End Select
If NoUnits <> 1 Then
Unita = Mid(Sezioni(S), 3, 1)
Uni = Converti(Unita)
If (Unita = "1" Or Unita = "8") And Dec <> "" Then Dec = Mid(Dec, 1, Len(Dec) - 1)
End If
End If
Sez(S) = Cent & Dec & Uni
Cent = "": Dec = "": Uni = ""
Next
Finale = ""
For X = 0 To Nsez - 1
Select Case Nsez - (X + 1)
Case 0
interp = ""
Case 1
If Sez(X) = "uno" Then
Sez(X) = ""
interp = "mille"
Else
interp = "mila"
End If
Case 2
If Sez(X) = "uno" Then
Sez(X) = "un"
interp = "milione"
Else
interp = "milioni"
End If
Case 3
If Sez(X) = "uno" Then
Sez(X) = "un"
interp = "miliardo"
Else
interp = "miliardi"
End If
End Select
Finale = Finale & Sez(X) & interp
Next
NumeriPerLettere = Finale & "/" & decimali
End Function
Function Converti(Numero)
If Numero = "1" Then Stringa = "uno"
If Numero = "2" Then Stringa = "due"
If Numero = "3" Then Stringa = "tre"
If Numero = "4" Then Stringa = "quattro"
If Numero = "5" Then Stringa = "cinque"
If Numero = "6" Then Stringa = "sei"
If Numero = "7" Then Stringa = "sette"
If Numero = "8" Then Stringa = "otto"
If Numero = "9" Then Stringa = "nove"
If Numero = "10" Then Stringa = "dieci"
If Numero = "11" Then Stringa = "undici"
If Numero = "12" Then Stringa = "dodici"
If Numero = "13" Then Stringa = "tredici"
If Numero = "14" Then Stringa = "quattordici"
If Numero = "15" Then Stringa = "quindici"
If Numero = "16" Then Stringa = "sedici"
If Numero = "17" Then Stringa = "diciassette"
If Numero = "18" Then Stringa = "diciotto"
If Numero = "19" Then Stringa = "diciannove"
If Numero = "20" Then Stringa = "venti"
If Numero = "30" Then Stringa = "trenta"
If Numero = "40" Then Stringa = "quaranta"
If Numero = "50" Then Stringa = "cinquanta"
If Numero = "60" Then Stringa = "sessanta"
If Numero = "70" Then Stringa = "settanta"
If Numero = "80" Then Stringa = "ottanta"
If Numero = "90" Then Stringa = "novanta"
If Numero = "100" Then Stringa = "cento"
Converti = Stringa
End Function
Non so se questo post è già presente nel forum, chiedo scusa in anticipo.
Espongo brevemente il mio problema,
ho trovato su internet alcune soluzioni al mio problema, ma purtroppo non funzionano correttamente.
in un report ho due campi uno denominato IMPMO e l'altro è un campo da una queri che viene fuori da una funzione che posto in calce:
Quando nel repor leggo nel campo IMPMO il valore 1.577,80 il campo della funzione mi riporta millecinquecentosettantasette/77
non so dive è l'errore.
ribadisco che questa funzione l'ho trovata su un forum.
Ciao a tutti e grazie a chi può darmi un aiuto.
Function NumeriPerLettere(VALORE) As String
VALORE = Replace(VALORE, ".", "")
Dim Sez()
Unita = ""
Decine = ""
Centinaia = ""
Uni = ""
Dec = ""
Cent = ""
Sezioni = ""
NoUnits = 0
'Ritorna se vi è; la virgola
numInt = InStr(VALORE, ",")
numDecim = Len(VALORE) - InStr(VALORE, ",") 'Controlla il numero dei decimali dopo la virgola
'Controlla se il numero è; privo di virgola
If numInt = 0 Then
VALORE = Left(VALORE, Len(VALORE))
'Mette come decimali due zeri
decimali = "00"
ElseIf numDecim = 1 Then 'Se c'è; un solo decimale dopo la virgola gli aggiunge uno zero
VALORE = Left(VALORE, Len(VALORE) - Len(Mid(VALORE, (InStr(VALORE, ",")))))
decimali = Right(VALORE, 1) & "0"
Else
VALORE = Left(VALORE, Len(VALORE) - Len(Mid(VALORE, (InStr(VALORE, ",")))))
'Mi restituisce i due decimali alla destra della virgola
decimali = Right(VALORE, 2)
End If
Cifre = Len(VALORE)
Stringa = ""
P = 0
For Posizione = 1 To Cifre
P = P + 1
Stringa = Mid(VALORE, Cifre - (Posizione - 1), 1) & Stringa
If P = 3 Then
Stringa = "\" & Stringa: P = 0
End If
Next
If Left(Stringa, 1) = "\" Then Stringa = Mid(Stringa, 2, Len(Stringa))
Sezioni = Empty
Sezioni = Split(Stringa, "\")
Nsez = UBound(Sezioni) + 1
Erase Sez()
ReDim Sez(Nsez)
For S = 0 To Nsez - 1
If Len(Sezioni(S)) < 3 Then Sezioni(S) = String(3 - Len(Sezioni(S)), "0") & Sezioni(S)
If Len(Sezioni(S)) = 3 Then
Centinaia = Mid(Sezioni(S), 1, 1)
Select Case Centinaia
Case "0"
Cent = ""
Case "1"
Cent = "cento"
Case Else
Cent = Converti(Centinaia) & "cento"
End Select
Decine = Mid(Sezioni(S), 2, 1)
Select Case Decine
Case "0"
Dec = ""
NoUnits = 0
Case "1"
Dec = Converti(Decine & Mid(Sezioni(S), 3, 1))
NoUnits = 1
Unita = ""
Case Else
Dec = Converti(Decine & "0")
NoUnits = 0
End Select
If NoUnits <> 1 Then
Unita = Mid(Sezioni(S), 3, 1)
Uni = Converti(Unita)
If (Unita = "1" Or Unita = "8") And Dec <> "" Then Dec = Mid(Dec, 1, Len(Dec) - 1)
End If
End If
Sez(S) = Cent & Dec & Uni
Cent = "": Dec = "": Uni = ""
Next
Finale = ""
For X = 0 To Nsez - 1
Select Case Nsez - (X + 1)
Case 0
interp = ""
Case 1
If Sez(X) = "uno" Then
Sez(X) = ""
interp = "mille"
Else
interp = "mila"
End If
Case 2
If Sez(X) = "uno" Then
Sez(X) = "un"
interp = "milione"
Else
interp = "milioni"
End If
Case 3
If Sez(X) = "uno" Then
Sez(X) = "un"
interp = "miliardo"
Else
interp = "miliardi"
End If
End Select
Finale = Finale & Sez(X) & interp
Next
NumeriPerLettere = Finale & "/" & decimali
End Function
Function Converti(Numero)
If Numero = "1" Then Stringa = "uno"
If Numero = "2" Then Stringa = "due"
If Numero = "3" Then Stringa = "tre"
If Numero = "4" Then Stringa = "quattro"
If Numero = "5" Then Stringa = "cinque"
If Numero = "6" Then Stringa = "sei"
If Numero = "7" Then Stringa = "sette"
If Numero = "8" Then Stringa = "otto"
If Numero = "9" Then Stringa = "nove"
If Numero = "10" Then Stringa = "dieci"
If Numero = "11" Then Stringa = "undici"
If Numero = "12" Then Stringa = "dodici"
If Numero = "13" Then Stringa = "tredici"
If Numero = "14" Then Stringa = "quattordici"
If Numero = "15" Then Stringa = "quindici"
If Numero = "16" Then Stringa = "sedici"
If Numero = "17" Then Stringa = "diciassette"
If Numero = "18" Then Stringa = "diciotto"
If Numero = "19" Then Stringa = "diciannove"
If Numero = "20" Then Stringa = "venti"
If Numero = "30" Then Stringa = "trenta"
If Numero = "40" Then Stringa = "quaranta"
If Numero = "50" Then Stringa = "cinquanta"
If Numero = "60" Then Stringa = "sessanta"
If Numero = "70" Then Stringa = "settanta"
If Numero = "80" Then Stringa = "ottanta"
If Numero = "90" Then Stringa = "novanta"
If Numero = "100" Then Stringa = "cento"
Converti = Stringa
End Function