Public dvt 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
Function Say(ByVal Number As Double, Unit, Dec) As String
bangchu(0, 0) = "Khoâng traêm "
bangchu(1, 0) = "Moät traêm "
bangchu(2, 0) = "Hai traêm "
bangchu(3, 0) = "Ba traêm "
bangchu(4, 0) = "Boán traêm "
bangchu(5, 0) = "Naêm traêm "
bangchu(6, 0) = "Saùu traêm "
bangchu(7, 0) = "Baûy traêm "
bangchu(8, 0) = "Taùm traêm "
bangchu(9, 0) = "Chín traêm "
bangchu(0, 1) = IIf(Int(Abs(Number)) = 0, "Khoâng ", " ")
bangchu(1, 1) = "Moät "
bangchu(2, 1) = "Hai "
bangchu(3, 1) = "Ba "
bangchu(4, 1) = "Boán "
bangchu(5, 1) = "Naêm "
bangchu(6, 1) = "Saùu "
bangchu(7, 1) = "Baûy "
bangchu(8, 1) = "Taùm "
bangchu(9, 1) = "Chín "
bangchu(0, 2) = "leû "
bangchu(1, 2) = "Möôøi "
bangchu(2, 2) = "Hai möôi "
bangchu(3, 2) = "Ba möôi "
bangchu(4, 2) = "Boán möôi "
bangchu(5, 2) = "Naêm möôi "
bangchu(6, 2) = "Saùu möôi "
bangchu(7, 2) = "Baûy möôi "
bangchu(8, 2) = "Taùm möôi "
bangchu(9, 2) = "Chín möôi "
banghang(0) = ""
banghang(1) = ""
banghang(2) = IIf(Number >= 1000 And Number Mod 1000 = 0, "ngaøn ", "ngaøn, ")
banghang(3) = IIf(Number >= 10 ^ 6 And Number Mod 10 ^ 6 = 0, "trieäu ", "trieäu, ")
banghang(4) = IIf(Number >= 10 ^ 9 And Number Mod 10 ^ 9 = 0, "tyû ", "tyû, ")
banghang(5) = "ngaøn tyû, "
bangvaloi(1, 1) = "möôi moät"
bangvaloi(2, 1) = "i naêm"
bangvaloi(1, 2) = "möôi moát"
bangvaloi(2, 2) = "i laêm"
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
Say = chu
Else
Say = Say & LCase(chu)
End If
End If
Next i
Say = Replace(Say, bangvaloi(1, 1), bangvaloi(1, 2))
Say = Replace(Say, bangvaloi(2, 1), bangvaloi(2, 2))
sole = Abs(Number) - Int(Abs(Number))
If sole > 0 Then
Select Case Unit
Case 0
dvt = ""
Case 1
dvt = "ñoàng"
Case 2
dvt = "Myõ kim"
Case 3
dvt = "Euro"
Case Else
dvt = Unit
End Select
Else
Select Case Unit
Case 0
dvt = IIf(Dec = 1, IIf(tam < 2, "cent", "cents"), IIf(Dec = 0, "", Dec))
Case 1
dvt = "ñoàng chaün"
Case 2
dvt = "Myõ kim chaün"
Case 3
dvt = "Euro chaün"
Case Else
dvt = Unit & " chaün"
End Select
End If
Select Case Number
Case 0
Say = ""
Case Is > 0
Say = Trim(Say & dvt)
Case Else
Say = "AÂm " & LCase(Say)
Say = Trim(Say & dvt)
End Select
If sole > 0 Then
Say = Trim(Say) & IIf(Dec = 0, " phaåy ", " vaø ")
Say = Say & IIf(Round(sole * 100, 0) < 10 And Dec = 0, "khoâng ", "")
Say = Say & LCase(Say(Round(sole * 100, 0), 0, Dec))
Else
Say = Say & "."
'Exceptions:
Say = IIf(tam > 1, Replace(Say, "penny", "pence"), Say)
Say = IIf(tam > 1, Replace(Say, "foot", "feet"), Say)
End If
'Exceptions:
Say = IIf(tam > 1, Replace(Say, "penny", "pence"), Say)
Say = IIf(tam > 1, Replace(Say, "foot", "feet"), Say)
End Function