Option Explicit
Dim Arr1 As Variant
Dim Arr10 As Variant
Dim Arr100 As Variant
Private Sub GetWords(Amt As Currency)
Dim d1 As Long
Dim d10 As Long
Dim d100 As Long
Dim d1000 As Long
Dim d100000 As Long
Dim d1000000 As Long
Dim c1 As Long
Dim c10 As Long
Dim Words As String
Dim Amount As Double
Dim tmpAmt As Double
'///////////////////////////
' Dollar Processing
'///////////////////////////
Amount = Amt
d1000000 = Int(Amount / 1000000): Amount = Amount - (d1000000 * 1000000)
d100000 = Int(Amount / 100000): Amount = Amount - (d100000 * 100000)
d1000 = Int(Amount / 1000): Amount = Amount - (d1000 * 1000)
d100 = Int(Amount / 100): Amount = Amount - CDbl(d100 * 100)
d10 = Int(Amount / 10): Amount = Amount - CDbl(d10 * 10)
d1 = Int(Amount): Amount = Amount - d1
'///////////////////////////
' Cents Processing
'///////////////////////////
Amount = Amount * 100
c10 = Int(Amount / 10): Amount = Amount - (c10 * 10)
c1 = Int(Amount): Amount = Amount - c1
Words = ""
'///////////////////////////
' Dollars Words Processing
'///////////////////////////
If d1000000 > 0 Then
If d1000000 < 19 Then
Amount = d1000000
Words = Words & Arr1(d1000000) & " Million "
Else
If d1000000 > 19 Then
Amount = d1000000
Words = Words & Arr100(Int(d1000000 / 10)): Amount = (d1000000 Mod 10)
If Amount > 0 Then Words = Words & " " & Arr1(Amount)
Words = Words & " Million "
Else
If d1000 = 0 Then Words = Words & Arr1(d1000000) & " Million "
End If
End If
End If
If d100000 > 0 Then
Words = Words & GetHundreds(Int(d100000 / 10)): Amount = (d100000 Mod 10)
If (Amount > 0 And d1000 = 0) Then
Words = Words & Arr1(d100000) & " Hundred Thousand "
Else
If d1000 > 0 Then Words = Words & Arr1(d100000) & " Hundred "
End If
End If
If d1000 > 19 Then
Amount = d1000
Words = Words & Arr100(Int(d1000 / 10)): Amount = (d1000 Mod 10)
If Amount > 0 Then Words = Words & " " & Arr1(Amount)
Words = Words & " Thousand "
Else
If d1000 > 0 Then Words = Words & Arr1(d1000) & " Thousand "
End If
Words = Words & GetHundreds(d100)
Words = Words & GetTens(d1, d10, " Dollars")
'///////////////////////////
' Cents Words Processing
'///////////////////////////
Words = Words & " and " & GetCents(c1, c10, " Cents")
MsgBox Words
Text1.Text = ""
End Sub
Function GetTens(iones As Long, itens As Long, stype As String) As String
Dim ones, tens As Integer
ones = iones
tens = itens
If ones > 0 And tens = 1 Then
GetTens = GetTens & Arr1(ones + (tens * 10)) & " "
ones = 0
Else
GetTens = GetTens & Arr100(tens) & " "
End If
If ones > 0 Then
GetTens = GetTens & Arr1(ones) & stype
Else
GetTens = stype
End If
End Function
Function GetCents(iones As Long, itens As Long, stype As String) As String
Dim ones, tens As Integer
ones = iones
tens = itens
If ones > 0 And tens = 1 Then
GetCents = GetCents & Arr1(ones + (tens * 10)) & " "
ones = 0
Else
GetCents = GetCents & Arr100(tens) & " "
End If
If ones > 0 Then
GetCents = GetCents & Arr1(ones) & stype
Else
GetCents = "Zero" & stype
End If
End Function
Function GetHundreds(iHundreds As Long) As String
If iHundreds > 0 Then GetHundreds = Arr1(iHundreds) & " Hundred "
End Function
Function GetHundredsThs(iHundreds As Long) As String
If iHundreds > 0 Then GetHundredsThs = Arr1(iHundreds) & " Hundred "
End Function
Private Sub Command1_Click()
GetWords CCur(Val(Text1.Text))
End Sub
Private Sub Form_Load()
Arr1 = Array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", _
"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", _
"Seventeen", "Eighteen", "Ninteen")
Arr10 = Array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine")
Arr100 = Array("", "Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety")
End Sub