Anthony1312002
Programmer
I was directed to this script that converts numerical amounts into words using Visual Basic. I'm trying to make some changes to it so that I can use it in ASP/VBScript but with no success. The variable I'm trying to convert and display is CashC1. I'm unfamiliar with functions such as ParsChunk, Chunk and GoSub. I hope someone is willing to help. Thanks in advance.
'--------------------------------------
Function cWord2(num)
'first set up two arrays to convert numbers to words
Dim BigOnes(9)
Dim SmallOnes(19)
'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
CashC1 = FormatCurrency(CashC1, "000000.00")
Dollars = Left(CashC1, 6)
Cents = Right(CashC1, 2)
Words = ""
'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 & " and " & Cents & "/100"
Text2.Text = Words
End 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
End Function
'--------------------------------------
Function cWord2(num)
'first set up two arrays to convert numbers to words
Dim BigOnes(9)
Dim SmallOnes(19)
'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
CashC1 = FormatCurrency(CashC1, "000000.00")
Dollars = Left(CashC1, 6)
Cents = Right(CashC1, 2)
Words = ""
'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 & " and " & Cents & "/100"
Text2.Text = Words
End 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
End Function