hn4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com
Full version available at http://4u.jcisio.com/r/article394.htm

Không rõ

Chuyển tiền từ số sang chữ USD (VB)

(của bạn Nguyen Vu Loc post lên VNN1)

Public Function USD(AMT)

Dim ToRead, Chuoi, Nhom, Word As String

Dim I, J As Byte, W, X, Y, Z As Double

Dim Donvi, HChuc, Khung

If AMT = 0 Then

ToRead = "None"

Else

Donvi = Array("None", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen")

HChuc = Array("None", "None", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety")

Khung = Array("None", "trillion", "billion", "million", "thousand", "dollars", "cents")

If AMT < 0 Then

ToRead = "Minus" & Space(1)

Else

ToRead = Space(0)

End If

Chuoi = Format(Abs(AMT), "###############.00")

Chuoi = Right(Space(15) & Chuoi, 18)

For I = 1 To 6

Nhom = Mid(Chuoi, I * 3 - 2, 3)

If Nhom <> Space(3) Then

Select Case Nhom

Case "000"

If I = 5 And Abs(AMT) > 1 Then

Word = "dollars" & Space(1)

Else

Word = Space(0)

End If

Case ".00"

Word = "only"

Case Else

X = Val(Left(Nhom, 1))

Y = Val(Mid(Nhom, 2, 1))

Z = Val(Right(Nhom, 1))

W = Val(Right(Nhom, 2))

If X = 0 Then

Word = Space(0)

Else

Word = Donvi(X) & Space(1) & "hundred" & Space(1)

If W > 0 And W < 21 Then

Word = Word & "and" & Space(1)

End If

End If

If I = 6 And Abs(AMT) > 1 Then

Word = "and" & Space(1) & Word

End If

If W < 20 And W > 0 Then

Word = Word & Donvi(W) & Space(1)

Else

If W >= 20 Then

Word = Word & HChuc(Y) & Space(1)

If Z > 0 Then

Word = Word & Donvi(Z) & Space(1)

End If

End If

End If

Word = Word & Khung(I) & Space(1)

End Select

ToRead = ToRead & Word

End If

Next I

End If

USD = UCase(Left(ToRead, 1)) & Mid(ToRead, 2)

End Function


hainam4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com