Attribute VB_Name = "ModuloNumeroInLettere"
'*** TESTED MODULE ***

Option Explicit

Public Function NumeroInLettere(m_importo As Currency) As String
   Dim aCipher(30) As String
   Dim nFract1, nFract2, nFract3, nExp As Integer
   Dim cNumber As String
   Dim Temp As Double
   aCipher(1) = ""
   aCipher(2) = "UNO"
   aCipher(3) = "DUE"
   aCipher(4) = "TRE"
   aCipher(5) = "QUATTRO"
   aCipher(6) = "CINQUE"
   aCipher(7) = "SEI"
   aCipher(8) = "SETTE"
   aCipher(9) = "OTTO"
   aCipher(10) = "NOVE"
   aCipher(11) = "DIECI"
   aCipher(12) = "UNDICI"
   aCipher(13) = "DODICI"
   aCipher(14) = "TREDICI"
   aCipher(15) = "QUATTORDICI"
   aCipher(16) = "QUINDICI"
   aCipher(17) = "SEDICI"
   aCipher(18) = "DICIASSETTE"
   aCipher(19) = "DICIOTTO"
   aCipher(20) = "DICIANNOVE"
   aCipher(21) = "VENTI"
   aCipher(22) = "TRENTA"
   aCipher(23) = "QUARANTA"
   aCipher(24) = "CINQUANTA"
   aCipher(25) = "SESSANTA"
   aCipher(26) = "SETTANTA"
   aCipher(27) = "OTTANTA"
   aCipher(28) = "NOVANTA"
   For nExp = 3 To 0 Step -1
      Temp = m_importo / 1000 ^ nExp
      nFract1 = Int(Temp)
      If nFract1 > 0 Then
         nFract2 = nFract1
         If nFract2 > 99 Then
            Temp = nFract2 / 100
            nFract3 = Int(Temp)
            nFract2 = nFract2 - nFract3 * 100
            If nFract3 = 1 Then
               cNumber = cNumber + "CENTO"
            Else
               cNumber = cNumber + aCipher(nFract3 + 1) + "CENTO"
            End If
         End If
         If nFract2 <= 20 Then
            cNumber = cNumber + aCipher(nFract2 + 1)
         Else
            Temp = nFract2 / 10
            nFract3 = Int(Temp)
            cNumber = cNumber + aCipher(nFract3 + 19)
            nFract2 = nFract2 - nFract3 * 10
            If nFract2 = 1 Or nFract2 = 8 Then
               cNumber = Left(cNumber, Len(cNumber) - 1)
            End If
            cNumber = cNumber + aCipher(nFract2 + 1)
         End If
         Select Case nExp
            Case Is = 1
               If nFract1 = 1 Then
                  cNumber = Left(cNumber, Len(cNumber) - 3) + "MILLE"
               Else
                  cNumber = cNumber + "MILA"
               End If
            Case Is = 2
               If nFract1 = 1 Then
                  cNumber = Left(cNumber, Len(cNumber) - 3) + "UNMILIONE"
               Else
                  cNumber = cNumber + "MILIONI"
               End If
            Case Is = 3
               'miliardi...
               'RaiseEvent Bluff(m_importo)
               If nFract1 = 1 Then
                  cNumber = "UNMILIARDO"
               Else
                  cNumber = cNumber + "MILIARDI"
               End If
         End Select
         m_importo = m_importo - nFract1 * 1000 ^ nExp
      End If
   Next

   NumeroInLettere = cNumber
   
End Function

