Public Function USD(AMT)
Dim Toread, chuoi, Nhom, word As String
Dim i, j As Byte, W, Y, x, 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 x > 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