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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write figres in words using VB 6

Status
Not open for further replies.

majed

Programmer
Aug 20, 2001
1
SA
I'm writting a program using VB 6. This program must prints bills contain figures.This figures need to be written in words for example $1025 in the bill will appear plus word one thousand twanty five.If anybody can help on that i'll be thankfull

Fred
 
From vb2the max,

'Convert a number into its textual equivalent.
'
' Pass True in the second argument if you want a null string when
' zero is passed.
' This is a recursive routine that is probably the most concise
' routines that solves the problem

Function NumberToWords(ByVal Number As Long, Optional BlankIfZero As Boolean) _
As String
Select Case Number
Case 0
NumberToWords = IIf(BlankIfZero, "", "Zero")
Case 1 To 19
NumberToWords = Choose(Number, "One", "Two", "Three", "Four", _
"Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", _
"Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", _
"Seventeen", "Eighteen", "Nineteen")
Case 20 To 99
NumberToWords = Choose(Number \ 10 - 1, "Twenty", "Thirty", _
"Fourty", "Fifty", "Sixty", "Seventy", "Eighty", _
"Ninety") & NumberToWords(Number Mod 10, True)
Case 100 To 999
NumberToWords = NumberToWords(Number \ 100) & "Hundred" & IIf _
(Number >= 200, "s", "") & NumberToWords(Number Mod 100, True)
Case 1000 To 999999
NumberToWords = NumberToWords(Number \ 1000) & "Thousand" & IIf _
(Number >= 2000, "s", "") & NumberToWords(Number Mod 1000, True)
Case 1000000 To 999999999
NumberToWords = NumberToWords(Number \ 1000000) & "Million" & IIf _
(Number >= 2000000, "s", "") & NumberToWords(Number Mod 1000000, _
True)
Case Is >= 1000000000
NumberToWords = NumberToWords(Number \ 1000000000) & "Billion" & _
IIf(Number >= 2000000000, "s", "") & NumberToWords(Number Mod _
1000000000, True)
End Select
End Function
Brad,
Free mp3 player,games and more.
 
There appear to be some issues with this routine.

The Words are "runon" e.g. there are NO spaces between the words as in:

? NumberToWords(106.25)
OneHundredSix


The function does not handle ANY form of decimal values (e.g. Change) as in:

? NumberToWords(0.25)
Zero


See faq181-76 for a soloution which generates a string which is suitable for "check writting" and provides (IMHO) a better soloution.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top