Results 1 to 4 of 4

010904, 00:57 #1Registered User
 Join Date
 Mar 2003
 Location
 Singapore
 Posts
 200
Unanswered: Convert a number to corresponding wordings!!!
Hi guys,
I have this particular invoicing system where I need to print bills.Is there a fuction to convert numbers to words as 1001 >one thousand and one.
I need to print the total amount in words.Is there a single function or any way to work around with this.
Thanks
Michael

010904, 01:11 #2Stuck on my opinions...
 Join Date
 Nov 2003
 Posts
 1,487
A function can be created to do this. There are some out there for crabs (check some VB forums). I have seen them before and I'm sure I have a couple in my code archives...somewhere . I suppose I could make one real quick but you may need to tweak it to suit your needs.

011504, 00:28 #3Stuck on my opinions...
 Join Date
 Nov 2003
 Posts
 1,487
OK then....here you go, I found this one...up to trillions should be good enough huh :
In the OnClick event of a command button (or whatever) copy & paste the following code:
Code:If IsNumeric(txtNumber) Then lblResult = NumToText(CDbl(txtNumber)) Else MsgBox"Please Note:@@" & "The entry supplied is not a true number." End If
Code:Private Function NumToText(dblValue As Double) As String Static ones(0 To 9) As String Static teens(0 To 9) As String Static tens(0 To 9) As String Static thousands(0 To 4) As String Dim i As Integer, nPosition As Integer Dim nDigit As Integer, bAllZeros As Integer Dim strResult As String, strTemp As String Dim tmpBuff As String ones(0) = "zero" ones(1) = "one" ones(2) = "two" ones(3) = "three" ones(4) = "four" ones(5) = "five" ones(6) = "six" ones(7) = "seven" ones(8) = "eight" ones(9) = "nine" teens(0) = "ten" teens(1) = "eleven" teens(2) = "twelve" teens(3) = "thirteen" teens(4) = "fourteen" teens(5) = "fifteen" teens(6) = "sixteen" teens(7) = "seventeen" teens(8) = "eighteen" teens(9) = "nineteen" tens(0) = "" tens(1) = "ten" tens(2) = "twenty" tens(3) = "thirty" tens(4) = "forty" tens(5) = "fifty" tens(6) = "sixty" tens(7) = "seventy" tens(8) = "eighty" tens(9) = "ninty" thousands(0) = "" thousands(1) = "thousand" thousands(2) = "million" thousands(3) = "billion" thousands(4) = "trillion" 'Trap errors On Error GoTo NumToTextError 'Get fractional part strResult = "and " & Format((dblValue  Int(dblValue)) * 100, "00") & "/100" 'Convert rest to string and process each digit strTemp = CStr(Int(dblValue)) 'Iterate through string For i = Len(strTemp) To 1 Step 1 'Get value of this digit nDigit = Val(Mid$(strTemp, i, 1)) 'Get column position nPosition = (Len(strTemp)  i) + 1 'Action depends on 1's, 10's or 100's column Select Case (nPosition Mod 3) Case 1 '1's position bAllZeros = False If i = 1 Then tmpBuff = ones(nDigit) & " " ElseIf Mid$(strTemp, i  1, 1) = "1" Then tmpBuff = teens(nDigit) & " " i = i  1 'Skip tens position ElseIf nDigit > 0 Then tmpBuff = ones(nDigit) & " " Else 'If next 10s & 100s columns are also 'zero, then don't show 'thousands' bAllZeros = True If i > 1 Then If Mid$(strTemp, i  1, 1) <> "0" Then bAllZeros = False End If End If If i > 2 Then If Mid$(strTemp, i  2, 1) <> "0" Then bAllZeros = False End If End If tmpBuff = "" End If If bAllZeros = False And nPosition > 1 Then tmpBuff = tmpBuff & thousands(nPosition / 3) & " " End If strResult = tmpBuff & strResult Case 2 'Tens position If nDigit > 0 Then strResult = tens(nDigit) & " " & strResult End If Case 0 'Hundreds position If nDigit > 0 Then strResult = ones(nDigit) & " hundred " & strResult End If End Select Next i 'Convert first letter to upper case If Len(strResult) > 0 Then strResult = UCase$(Left$(strResult, 1)) & Mid$(strResult, 2) End If EndNumToText: 'Return result NumToText = strResult Exit Function NumToTextError: strResult = "#Error#" Resume EndNumToText End Function

011504, 01:57 #4Registered User
 Join Date
 Oct 2003
 Location
 Ger
 Posts
 1,969
Provided Answers: 1