Bạn làm thử cái này xem
Nhập đoạn mã lệnh sau:
Public Function phi(baonhieu)
Dim ketqua, sotien, nhom, chu, dich, s1, s2, s3 As String
Dim i, j, vitri As Byte, s As Double
Dim hang, doc, dem
If baonhieu = 0 Then
ketqua = "khoâng ñoàng"
Else
If Abs(baonhieu) >= 1E+15 Then
ketqua = "soá quaù lôùn"
Else
If baonhieu < 0 Then
ketqua = "tröø" & Space(1)
Else
ketqua = Space(0)
End If
sotien = Format(Abs(baonhieu), "##############0.00")
sotien = Right(Space(15) & sotien, 18)
hang = Array("none", "traêm", "möôi", "gì ñoù")
doc = Array("none", "ngaøn tyû", "tyû", "trieäu", "ngaøn", "ñoàng", "chaün")
dem = Array("none", "moät", "hai", "ba", "boán", "naêm", "saùu", "baûy", "taùm", "chín")
For i = 1 To 6
nhom = Mid(sotien, i * 3 - 2, 3)
If nhom <> Space(3) Then
Select Case nhom
Case "000"
If i = 5 Then
chu = "ñoàng" & Space(1)
Else
chu = Space(0)
End If
Case ".00"
chu = "chaün"
Case Else
s1 = Left(nhom, 1)
s2 = Mid(nhom, 2, 1)
s3 = Right(nhom, 1)
chu = Space(0)
hang(3) = doc(i)
For j = 1 To 3
dich = Space(0)
s = Val(Mid(nhom, j, 1))
If s > 0 Then
dich = dem(s) & Space(1) & hang(j) & Space(1)
End If
Select Case j
Case 2 And s = 1
dich = "möôøi" & Space(1)
Case 3 And s = 0 And nhom <> Space(2) & "0"
dich = hang(j) & Space(1)
Case 3 And s = 5 And s2 <> Space(1) And s2 <> "0"
dich = "l" & Mid(dich, 2)
Case 2 And s = 0 And s3 <> "0"
If (s1 >= "1" And s1 <= "9") Or (s1 = "0" And i = 4) Then
dich = "leû" & Space(1)
End If
End Select
chu = chu & dich
Next j
End Select
vitri = InStr(1, chu, "möôi moät", 1)
If vitri > 0 Then Mid(chu, vitri, 9) = "möôi moát"
ketqua = ketqua & chu
End If
Next i
End If
End If
Phi = UCase(Left(ketqua, 1)) & Mid(ketqua, 2)
End Function
Public Function usd(baonhieu)
Dim ketqua, sotien, nhom, chu, dich, s1, s2, s3 As String
Dim i, j, vitri As Byte, s As Double
Dim hang, doc, dem
If baonhieu = 0 Then
ketqua = "khoâng dollars"
Else
If Abs(baonhieu) >= 1E+15 Then
ketqua = "soá quaù lôùn"
Else
If baonhieu < 0 Then
ketqua = "tröø" & Space(1)
Else
ketqua = Space(0)
End If
sotien = Format(Abs(baonhieu), "##############0.00")
sotien = Right(Space(15) & sotien, 18)
hang = Array("none", "traêm", "möôi", "gì ñoù")
doc = Array("none", "ngaøn tyû", "tyû", "trieäu", "ngaøn", "dollars", "cents")
dem = Array("none", "moät", "hai", "ba", "boán", "naêm", "saùu", "baûy", "taùm", "chín")
For i = 1 To 6
nhom = Mid(sotien, i * 3 - 2, 3)
If nhom <> Space(3) Then
Select Case nhom
Case "000"
If i = 5 Then
chu = "dollars" & Space(1)
Else
chu = Space(0)
End If
Case ".00"
chu = "chaün"
Case Else
s1 = Left(nhom, 1)
s2 = Mid(nhom, 2, 1)
s3 = Right(nhom, 1)
chu = Space(0)
hang(3) = doc(i)
For j = 1 To 3
dich = Space(0)
s = Val(Mid(nhom, j, 1))
If s > 0 Then
dich = dem(s) & Space(1) & hang(j) & Space(1)
End If
Select Case j
Case 2 And s = 1
dich = "möôøi" & Space(1)
Case 3 And s = 0 And nhom <> Space(2) & "0"
dich = hang(j) & Space(1)
Case 3 And s = 5 And s2 <> Space(1) And s2 <> "0"
dich = "l" & Mid(dich, 2)
Case 2 And s = 0 And s3 <> "0"
If (s1 >= "1" And s1 <= "9") Or (s1 = "0" And i = 4) Then
dich = "leû" & Space(1)
End If
End Select
chu = chu & dich
Next j
End Select
vitri = InStr(1, chu, "möôi moät", 1)
If vitri > 0 Then Mid(chu, vitri, 9) = "möôi moát"
ketqua = ketqua & chu
End If
Next i
End If
End If
usd = UCase(Left(ketqua, 1)) & Mid(ketqua, 2)
End Function