# Thread: Words to numbers function (2000)

1. ## Words to numbers function (2000)

I have the following function in the db, but on 100000 it lists one hundred and thousand

We are usign it to convert a price to number , any ideaS?

2. ## Re: Words to numbers function (2000)

"the following function"? <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

3. ## Re: Words to numbers function (2000)

'Declare some general working variables.
Dim English, strNum, Chunk, Pennies As String
Dim Hundreds, Tens, Ones As Integer
Dim StartVal, LoopCount As Integer
Dim TensDone As Boolean
Dim varword As Variable

'Make array of number words called EngNum.
Dim EngNum(90) As String
EngNum(0) = ""
EngNum(1) = "One"
EngNum(2) = "Two"
EngNum(3) = "Three"
EngNum(4) = "Four"
EngNum(5) = "Five"
EngNum(6) = "Six"
EngNum(7) = "Seven"
EngNum(8) = "Eight"
EngNum(9) = "Nine"
EngNum(10) = "Ten"
EngNum(11) = "Eleven"
EngNum(12) = "Twelve"
EngNum(13) = "Thirteen"
EngNum(14) = "Fourteen"
EngNum(15) = "Fifteen"
EngNum(16) = "Sixteen"
EngNum(17) = "Seventeen"
EngNum(18) = "Eighteen"
EngNum(19) = "Nineteen"
EngNum(20) = "Twenty"
EngNum(30) = "Thirty"
EngNum(40) = "Forty"
EngNum(50) = "Fifty"
EngNum(60) = "Sixty"
EngNum(70) = "Seventy"
EngNum(80) = "Eighty"
EngNum(90) = "Ninety"

'** If xero or null passed, just return "VOID"
If Nz(AmountPassed) = 0 Then
NumWord = "VOID"
Exit Function
End If

'** strNum is the passed number converted to a string.
strNum = Format(AmountPassed, "000000000.00")

'Pennies variable contains last two digits of strNum
Pennies = Mid(strNum, 11, 2)

'Prep other variables for storage.
English = ""
LoopCount = 1
StartVal = 1

'** Now do each 3-digit section of number.
Do While LoopCount <= 3
Chunk = Mid(strNum, StartVal, 3) '3-digit chunk
Hundreds = Val(Mid(Chunk, 1, 1)) 'Hundreds portion
Tens = Val(Mid(Chunk, 2, 2)) 'Tens portion
Ones = Val(Mid(Chunk, 3, 1)) 'Ones portion

'** Do the hundreds portion of 3-digit number
If Val(Chunk) > 99 Then
English = English & EngNum(Hundreds) & " Hundred and "
End If

'** Do the tens & ones portion of 3-digit number
TensDone = False
'** Is it less than 10?
If Tens < 10 Then
English = English & " " & EngNum(Ones)
TensDone = True
End If

'** Is it a teen?
If (Tens >= 11 And Tens <= 19) Then
English = English & EngNum(Tens)
TensDone = True
End If

'** Is it evenly divisible by 10?
If (Tens / 10) = Int(Tens / 10) Then
English = English & EngNum(Tens)
TensDone = True
End If

'** Or is it none of the above?
If Not TensDone Then
English = English & EngNum((Int(Tens / 10)) * 10)
English = English & " " & EngNum(Ones)
End If

'** Add the word "Million" if necessary
If AmountPassed > 999999.99 And LoopCount = 1 Then
English = English + " Million "
End If

'** Add the word "Thousand" if necessary
If AmountPassed > 999.99 And LoopCount = 2 Then
English = English & " Thousand "
End If

'** Do pass through next three digits
LoopCount = LoopCount + 1
StartVal = StartVal + 3
Loop

'** Done: Return English with Pennies/100 tacked on
NumWord = Trim(English) & " pounds"

End Function

4. ## Re: Words to numbers function (2000)

Hi Luke

I seem to have this bookmarked, obviously some project that never got off the ground. It seems to work along the same lines as you are running and is broken down into 1's, 10's, 100's and 1000's. may help you

Convert numbers to words

5. ## Re: Words to numbers function (2000)

Try the attached version. I have done the following:
<UL><LI>Corrected the declarations - in a line such as

Dim Hundreds, Tens, Ones As Integer

Hundreds and Tens are *not* declared as integers, but as variants. It should be

Dim Hundreds As integer, Tens as Integer, Ones As Integer

The declaration

Dim varword As Variable

is incorrect and superfluous, as this variable is never used.
<LI>Applied consistent indentation. Code is hard to read if indentation is absent or applied haphazardly.
<LI>Removed the references to Pennies since they were ignored anyway.
<LI>Added a few lines to add " and " only when needed.[/list]

6. ## Re: Words to numbers function (2000)

thanks

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•