Public dvt As String
Public chu As String
Public bangchu(0 To 9, 0 To 2) As String
Public banghang(0 To 5) As String
Public bangvaloi(1 To 9, 1 To 2) As String
Public i As Integer
Public sole As Single
Public l As Integer
Public so As Integer
Public so1 As Integer
Public so2 As Integer
Public so3 As Integer
Public so4 As Integer
Public nhom As Integer
Public du As Integer
Function SayF(number, unit, dec) As String
bangchu(0, 0) = "Zero cent "
bangchu(1, 0) = "Un cent "
bangchu(2, 0) = "Deux cent "
bangchu(3, 0) = "Trois cent "
bangchu(4, 0) = "Quatre cent "
bangchu(5, 0) = "Cinq cent "
bangchu(6, 0) = "Six cent "
bangchu(7, 0) = "Sept cent "
bangchu(8, 0) = "Huit cent "
bangchu(9, 0) = "Neuf cent "
bangchu(0, 1) = IIf(Int(Abs(number)) = 0, "Zero ", " ")
bangchu(1, 1) = "Un "
bangchu(2, 1) = "Deux "
bangchu(3, 1) = "Trois "
bangchu(4, 1) = "Quatre "
bangchu(5, 1) = "Cinq "
bangchu(6, 1) = "Six "
bangchu(7, 1) = "Sept "
bangchu(8, 1) = "Huit "
bangchu(9, 1) = "Neuf "
bangchu(0, 2) = "et "
bangchu(1, 2) = "Dix "
bangchu(2, 2) = "Vingt "
bangchu(3, 2) = "Trente "
bangchu(4, 2) = "Quarante "
bangchu(5, 2) = "Cinquante "
bangchu(6, 2) = "Soixante "
bangchu(7, 2) = "Soixante-dix "
bangchu(8, 2) = "Quatre-vingt "
bangchu(9, 2) = "Quatre-vingt-dix "
banghang(0) = " "
banghang(1) = " "
banghang(2) = "mille, "
banghang(3) = "million "
banghang(4) = "milliard, "
banghang(5) = "thousand milliard, "
bangvaloi(1, 1) = "Dix un"
bangvaloi(1, 2) = "Onze"
bangvaloi(2, 1) = "Dix deux"
bangvaloi(2, 2) = "douze"
bangvaloi(3, 1) = "Dix trois"
bangvaloi(3, 2) = "Treize"
bangvaloi(4, 1) = "Dix quatre"
bangvaloi(4, 2) = "Quatoze"
bangvaloi(5, 1) = "Dix cinq"
bangvaloi(5, 2) = "Quinze"
bangvaloi(6, 1) = "Dix six"
bangvaloi(6, 2) = "Seize"
bangvaloi(7, 1) = "Dix sept"
bangvaloi(7, 2) = "Dix-sept"
bangvaloi(8, 1) = "Dix huit"
bangvaloi(8, 2) = "Dix-huit"
bangvaloi(9, 1) = "Dix neuf"
bangvaloi(9, 2) = "Dix-neuf"
tam = Abs(number)
tam = Int(tam)
l = Len(tam)
For i = 1 To l
so = Mid(tam, i, 1)
so1 = IIf(i > l - 1, 0, Mid(tam, i + 1, 1))
so2 = IIf(i > l - 2, 0, Mid(tam, i + 2, 1))
If i < 2 Then
so3 = 0
Else
so3 = Mid(tam, i - 1, 1)
End If
If i < 3 Then
so4 = 0
Else
so4 = Mid(tam, i - 2, 1)
End If
nhom = Int(l - i + 1) / 3 + 1
du = (l - i + 1) Mod 3
If ((du = 0) And (so = 0) And (so1 = 0) And (so2 = 0)) Or ((du = 2) And (so = 0) And (so1 = 0)) = True Then
chu = " "
Else
chu = bangchu(so, du)
End If
If (du = 1) And ((so <> 0) Or (so3 <> 0) Or (so4 <> 0)) Then
chu = chu & banghang(nhom)
End If
If chu <> " " Then
If i = 1 Then
SayF = chu
Else
SayF = SayF & LCase(chu)
End If
End If
Next i
For x = 1 To 9
SayF = Replace(SayF, bangvaloi(x, 1), bangvaloi(x, 2))
SayF = Replace(SayF, LCase(bangvaloi(x, 1)), LCase(bangvaloi(x, 2)))
Next x
sole = Abs(number) - Int(Abs(number))
If sole > 0 Then
Select Case unit
Case 0
dvt = ""
Case 1
dvt = IIf(tam < 2, "VN dong", "VN dongs")
Case 2
dvt = IIf(tam < 2, "US dollar", "US dollars")
Case 3
dvt = IIf(tam < 2, "Euro", "Euros")
Case Else
dvt = IIf(tam < 2, unit, unit & "s")
End Select
Else
Select Case unit
Case 0
dvt = IIf(dec = 1, IIf(tam < 2, "cent", "cents"), IIf(dec = 0, "", IIf(tam < 2, dec, dec & "s")))
Case 1
dvt = IIf(tam < 2, "VN dong only", "VN dongs only")
Case 2
dvt = IIf(tam < 2, "US dollar only", "US dollars only")
Case 3
dvt = IIf(tam < 2, "Euro only", "Euros only")
Case Else
dvt = IIf(tam < 2, unit, unit & "s") & " only"
End Select
End If
Select Case number
Case 0
SayF = " "
Case Is > 0
SayF = Trim(SayF & dvt)
Case Else
SayF = "Minus " & LCase(SayF)
SayF = Trim(SayF & dvt)
End Select
If sole > 0 Then
SayF = Trim(SayF) & IIf(dec = 0, " point ", " and ")
SayF = SayF & IIf(Round(sole * 100, 0) < 10 And dec = 0, "zero ", "")
SayF = SayF & LCase(SayF(Round(sole * 100, 0), 0, dec))
Else
SayF = SayF & "."
End If
'Exceptions:
SayF = Replace(SayF, "pennys", "pence")
SayF = Replace(SayF, "mouses", "mice")
SayF = Replace(SayF, "foots", "feet")
End Function