Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CHANGING 1234 TO "ONE THOUSAND TWO HUNDRED THIRTY FOUR"? 1

Status
Not open for further replies.

VOGEL24

Programmer
Jan 27, 2004
6
US
I have a form for creating propsals for jobs.

ProposalTotal Field has a formula to calculate total proposal from other fields.

TotalWrittenPropsal Field where user types in written bid amount.

Is there any way to convert the number to words?

Thanks
VOGEL24

 
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




End Function


HTH,

Steve
 
Steve,

Thanks a 1,000,000 or should I say million.

Mary
 
Mary,

No problem. I can not take create for the code I had it a code library from many moons ago but I know it works.

:)

Steve
 
faq1811740 It includes an option to NOT format as "decimal".

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top