# Number to Word Convertion

Converts Number into words up to 999 trillion. It is a simple short code.

Original Author: Opal Raj Ghimire

### Code

`Number to words, fairly small codeOpal R. Ghimire, Kathmandu, email:buna48@hotmail.com?á`

`'THIS FUNCTION CONVERTS 1 TO 999 TRILLION INTO WORDSPublic Function ToWords(NumAs String) As StringDim sFormated As String, Unit As String, Ans(5) As StringDim K As Integer, K1 As IntegerAns(0) = "trillion ": Ans(1) = "billion ": Ans(2) = "million "Ans(3) = "thousand ": Ans(4) = ""sFormated = Format(Num, "000000000000000.00")For K = 1 To 13 Step 3?á?á?áUnit = Mid\$(sFormated, K, 3)?á?á?á If Val(Unit) > 0 Then ToWords = ToWords + ToNum(Unit) + Ans(K1)?á?á?áK1 = K1 + 1Next'HANDLES DECIMAL PARTS (IF ANY)If Val(Num) - Int(Num) <> 0 Then ToWords = ToWords + "and " + Right\$(sFormated, 2) + "/100"End Function'THIS FUNCTION CONVERTS 1 TO 999 INTO WORDSPublic Function ToNum(Num As String) As StringDim N(19) As String, NN(8) As String, Formated As StringDim Hun As Integer, Tens As IntegerN(0) = "": N(1) = "one": N(2) = "two": N(3) = "three": N(4) = "four": N(5) = "five": N(6) = "six": N(7) = "seven": N(8) = "eight": N(9) = "nine": N(10) = "ten": N(11) = "eleven"N(12) = "twelve": N(13) = "thirteen": N(14) = "fourteen": N(15) = "fifteen": N(16) = "sixteen": N(17) = "seventeen": N(18) = "eighteen": N(19) = "nineteen"NN(0) = "twenty": NN(1) = "thirty": NN(2) = "forty": NN(3) = "fifty": NN(4) = "sixty": NN(5) = "seventy": NN(6) = "eighty": NN(7) = "ninety"Formated = Format(Num, "000.00")Hun = Mid\$(Formated, 1, 1)Tens = Mid\$(Formated, 2, 2)If Hun <> 0 Then ToNum = N(Hun) + " hundred "If Tens <> 0 Then?á?á?á If Tens < 20 Then?á?á?á?á?á?á?áToNum = ToNum + N(Tens) + " "?á?á?á Else '>20?á?á?á?á?á?á?áToNum = ToNum + NN(Mid(Tens, 1, 1) - 2) + " " + N(Mid(Tens, 2, 1)) + " "?á?á?á End IfEnd If 'Tens <> 0End Function`

Posted: 2003-06-01
By: ArchiveBot
Viewed: 136 times

Categories

Visual Basic 6

Attachments

No attachments for this post