You will need to pass your numeric value to the following function as a string (In other words use Str([Numeric]) -
Public Function Convert_Dollar(iDollar As String) As String
'first set up two arrays to convert numbers to words
Dim BigOnes(9) As String
Dim SmallOnes(19) As String
Dim Dollars As String
Dim cents As String
Dim Words As String
Dim Chunk As String
Dim digits As String
Dim leftDigit As String
Dim RightDigit As String
'and populate them
BigOnes(1) = "Ten"
BigOnes(2) = "Twenty"
BigOnes(3) = "Thirty"
BigOnes(4) = "Forty"
BigOnes(5) = "Fifty"
BigOnes(6) = "Sixty"
BigOnes(7) = "Seventy"
BigOnes(8) = "Eighty"
BigOnes(9) = "Ninety"
SmallOnes(1) = "One"
SmallOnes(2) = "Two"
SmallOnes(3) = "Three"
SmallOnes(4) = "Four"
SmallOnes(5) = "Five"
SmallOnes(6) = "Six"
SmallOnes(7) = "Seven"
SmallOnes(8) = "Eight"
SmallOnes(9) = "Nine"
SmallOnes(10) = "Ten"
SmallOnes(11) = "Eleven"
SmallOnes(12) = "Twelve"
SmallOnes(13) = "Thirteen"
SmallOnes(14) = "Fourteen"
SmallOnes(15) = "Fifteen"
SmallOnes(16) = "Sixteen"
SmallOnes(17) = "Seventeen"
SmallOnes(18) = "Eighteen"
SmallOnes(19) = "Nineteen"
'format the incoming number to guarantee six digits
'to the left of the decimal point and two to the right
'and then separate the dollars from the cents
iDollar = Format(iDollar, "000000.00"
Dollars = Left(iDollar, 6)
cents = Right(iDollar, 2)
Words = ""
'check to make sure incoming number is not too large
If Dollars > 999999 Then
'Text2.Text = "Dollar amount is too large"
Exit Function
End If
'separate the dollars into chunks
If Dollars = 0 Then
Words = "Zero"
Else
'first do the thousands
Chunk = Left(Dollars, 3)
If Chunk > 0 Then
GoSub ParseChunk
Words = Words & " Thousand"
End If
'do the rest of the dollars
Chunk = Right(Dollars, 3)
If Chunk > 0 Then
GoSub ParseChunk
End If
End If
'concatenate the cents and display
If cents = 0 Then cents = "No"
Words = Words & " & " & cents & "/100"
'Text2.Text = Words
Convert_Dollar = Words
Exit Function
ParseChunk: digits = Mid(Chunk, 1, 1)
If digits > 0 Then
Words = Words & " " & SmallOnes(digits) & " Hundred"
End If
digits = Mid(Chunk, 2, 2)
If digits > 19 Then
leftDigit = Mid(Chunk, 2, 1)
RightDigit = Mid(Chunk, 3, 1)
Words = Words & " " & BigOnes(leftDigit)
If RightDigit > 0 Then
Words = Words & " " & SmallOnes(RightDigit)
End If
Else
If digits > 0 Then
Words = Words & " " & SmallOnes(digits)
End If
End If
Return
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.