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

Changing Numbers into text...

Status
Not open for further replies.

PaulChilds

Technical User
May 21, 2002
195
I have a module which changes numbers into text, so, eg, if I type 10000, it shows 'Ten Thousand' and the appropriate place. However I have a problem with the word 'and'.

When I want it to say "One Thousand and One", it shows "One Thousand One" instead. It happens when it should be "thousand/million/billion and", but it works with the hundreds (eg 105 shows 'One Hundred and Five'), so 1205 works (it shows 'One Thousand Two Hundred and Five') etc.

Below is the code I am using. I can't work out where the problem is.

Any ideas?

Paul C

PS - It's called Spellpound because it's part of a finacial database - there's no relevance of the word pound otherwise.


Function SpellPound(dblValue As Double) As String

' Usage - To test it, open the debug window (ctrl+G) and type: ?SpellPound(any number you want), and hit enter

Dim centspot As Integer, Poundlen As Integer
Dim Pounds As Double, Cents As Integer
Dim Hundreds As Integer, Thousands As Integer
Dim Millions As Integer, Billions As Integer
Dim centtext As String, huntext As String, thoutext As String
Dim milltext As String, billtext As String, temptext As String

If dblValue < 0.01 Then
temptext = &quot;Zero&quot;
Else
centspot = InStr(dblValue, &quot;.&quot;)
If centspot > 0 Then
Cents = Right(dblValue, 2)
Pounds = Left(dblValue, centspot - 1)
Else
Cents = 0
Pounds = dblValue
End If

Poundlen = Len(CStr(Pounds))

If Poundlen > 0 Then
Select Case Pounds
Case 1 To 999
Select Case Pounds
Case 1 To 9
Hundreds = Right(Pounds, 1)
Case 10 To 99
Hundreds = Right(Pounds, 2)
Case 100 To 999
Hundreds = Right(Pounds, 3)
End Select
Case 1000 To 999999
Hundreds = Right(Pounds, 3)
Select Case Pounds
Case 1000 To 9999
Thousands = Left(Pounds, 1)
Case 10000 To 99999
Thousands = Left(Pounds, 2)
Case 100000 To 999999
Thousands = Left(Pounds, 3)
End Select
Case 1000000 To 999999999
Hundreds = Right(Pounds, 3)
Thousands = Mid(Pounds, (Poundlen - 5), 3)
Select Case Pounds
Case 1000000 To 9999999
Millions = Left(Pounds, 1)
Case 10000000 To 99999999
Millions = Left(Pounds, 2)
Case 100000000 To 999999999
Millions = Left(Pounds, 3)
End Select
Case 1000000000 To 999999999999#
Hundreds = Right(Pounds, 3)
Thousands = Mid(Pounds, (Poundlen - 5), 3)
Millions = Mid(Pounds, (Poundlen - 8), 3)
Select Case Pounds
Case 1000000000 To 9999999999#
Billions = Left(Pounds, 1)
Case 10000000000# To 99999999999#
Billions = Left(Pounds, 2)
Case 100000000000# To 999999999999#
Billions = Left(Pounds, 3)
End Select
End Select
End If

If Hundreds > 0 Then huntext = GetPoundString(&quot;hundreds&quot;, Hundreds)
If Thousands > 0 Then thoutext = GetPoundString(&quot;thousands&quot;, Thousands)
If Millions > 0 Then milltext = GetPoundString(&quot;millions&quot;, Millions)
If Billions > 0 Then billtext = GetPoundString(&quot;billions&quot;, Billions)




If billtext = &quot;&quot; Then
If milltext = &quot;&quot; Then
If thoutext = &quot;&quot; Then
If huntext = &quot;&quot; Then
temptext = centtext
Else
temptext = huntext
End If
Else
temptext = thoutext & &quot; &quot; & huntext
End If
Else
temptext = milltext & &quot; &quot; & thoutext & &quot; &quot; & huntext
End If
Else
temptext = billtext & &quot; &quot; & milltext & &quot; &quot; & thoutext & huntext
End If
End If



SpellPound = Trim(temptext)
End Function

Function GetPoundString(strPart As String, intPart As Integer) As String
Dim strPounds As String
If Right(Pounds, 2) = 0 Then
Select Case Mid(intPart, 1, 1)
Case 1: strPounds = &quot;One Hundred and&quot;
Case 2: strPounds = &quot;Two Hundred and&quot;
Case 3: strPounds = &quot;Three Hundred and&quot;
Case 4: strPounds = &quot;Four Hundred and&quot;
Case 5: strPounds = &quot;Five Hundred and&quot;
Case 6: strPounds = &quot;Six Hundred and&quot;
Case 7: strPounds = &quot;Seven Hundred and&quot;
Case 8: strPounds = &quot;Eight Hundred and&quot;
Case 9: strPounds = &quot;Nine Hundred and&quot;
End Select
Else
If intPart > 99 Then
Select Case Mid(intPart, 1, 1)
Case 1: strPounds = &quot;One Hundred&quot;
Case 2: strPounds = &quot;Two Hundred&quot;
Case 3: strPounds = &quot;Three Hundred&quot;
Case 4: strPounds = &quot;Four Hundred&quot;
Case 5: strPounds = &quot;Five Hundred&quot;
Case 6: strPounds = &quot;Six Hundred&quot;
Case 7: strPounds = &quot;Seven Hundred&quot;
Case 8: strPounds = &quot;Eight Hundred&quot;
Case 9: strPounds = &quot;Nine Hundred&quot;
End Select
End If
End If

Select Case Right(intPart, 2)
Case 1: strPounds = strPounds & &quot; and One&quot;
Case 2: strPounds = strPounds & &quot; and Two&quot;
Case 3: strPounds = strPounds & &quot; and Three&quot;
Case 4: strPounds = strPounds & &quot; and Four&quot;
Case 5: strPounds = strPounds & &quot; and Five&quot;
Case 6: strPounds = strPounds & &quot; and Six&quot;
Case 7: strPounds = strPounds & &quot; and Seven&quot;
Case 8: strPounds = strPounds & &quot; and Eight&quot;
Case 9: strPounds = strPounds & &quot; and Nine&quot;
Case 10: strPounds = strPounds & &quot; and Ten&quot;
Case 11: strPounds = strPounds & &quot; and Eleven&quot;
Case 12: strPounds = strPounds & &quot; and Twelve&quot;
Case 13: strPounds = strPounds & &quot; and Thirteen&quot;
Case 14: strPounds = strPounds & &quot; and Fourteen&quot;
Case 15: strPounds = strPounds & &quot; and Fifteen&quot;
Case 16: strPounds = strPounds & &quot; and Sixteen&quot;
Case 17: strPounds = strPounds & &quot; and Seventeen&quot;
Case 18: strPounds = strPounds & &quot; and Eighteen&quot;
Case 19: strPounds = strPounds & &quot; and Nineteen&quot;
Case 20: strPounds = strPounds & &quot; and Twenty&quot;
Case 21: strPounds = strPounds & &quot; and Twenty One&quot;
Case 22: strPounds = strPounds & &quot; and Twenty Two&quot;
Case 23: strPounds = strPounds & &quot; and Twenty Three&quot;
Case 24: strPounds = strPounds & &quot; and Twenty Four&quot;
Case 25: strPounds = strPounds & &quot; and Twenty Five&quot;
Case 26: strPounds = strPounds & &quot; and Twenty Six&quot;
Case 27: strPounds = strPounds & &quot; and Twenty Seven&quot;
Case 28: strPounds = strPounds & &quot; and Twenty Eight&quot;
Case 29: strPounds = strPounds & &quot; and Twenty Nine&quot;
Case 30: strPounds = strPounds & &quot; and Thirty&quot;
Case 31: strPounds = strPounds & &quot; and Thirty One&quot;
Case 32: strPounds = strPounds & &quot; and Thirty Two&quot;
Case 33: strPounds = strPounds & &quot; and Thirty Three&quot;
Case 34: strPounds = strPounds & &quot; and Thirty Four&quot;
Case 35: strPounds = strPounds & &quot; and Thirty Five&quot;
Case 36: strPounds = strPounds & &quot; and Thirty Six&quot;
Case 37: strPounds = strPounds & &quot; and Thirty Seven&quot;
Case 38: strPounds = strPounds & &quot; and Thirty Eight&quot;
Case 39: strPounds = strPounds & &quot; and Thirty Nine&quot;
Case 40: strPounds = strPounds & &quot; and Forty&quot;
Case 41: strPounds = strPounds & &quot; and Forty One&quot;
Case 42: strPounds = strPounds & &quot; and Forty Two&quot;
Case 43: strPounds = strPounds & &quot; and Forty Three&quot;
Case 44: strPounds = strPounds & &quot; and Forty Four&quot;
Case 45: strPounds = strPounds & &quot; and Forty Five&quot;
Case 46: strPounds = strPounds & &quot; and Forty Six&quot;
Case 47: strPounds = strPounds & &quot; and Forty Seven&quot;
Case 48: strPounds = strPounds & &quot; and Forty Eight&quot;
Case 49: strPounds = strPounds & &quot; and Forty Nine&quot;
Case 50: strPounds = strPounds & &quot; and Fifty&quot;
Case 51: strPounds = strPounds & &quot; and Fifty One&quot;
Case 52: strPounds = strPounds & &quot; and Fifty Two&quot;
Case 53: strPounds = strPounds & &quot; and Fifty Three&quot;
Case 54: strPounds = strPounds & &quot; and Fifty Four&quot;
Case 55: strPounds = strPounds & &quot; and Fifty Five&quot;
Case 56: strPounds = strPounds & &quot; and Fifty Six&quot;
Case 57: strPounds = strPounds & &quot; and Fifty Seven&quot;
Case 58: strPounds = strPounds & &quot; and Fifty Eight&quot;
Case 59: strPounds = strPounds & &quot; and Fifty Nine&quot;
Case 60: strPounds = strPounds & &quot; and Sixty&quot;
Case 61: strPounds = strPounds & &quot; and Sixty One&quot;
Case 62: strPounds = strPounds & &quot; and Sixty Two&quot;
Case 63: strPounds = strPounds & &quot; and Sixty Three&quot;
Case 64: strPounds = strPounds & &quot; and Sixty Four&quot;
Case 65: strPounds = strPounds & &quot; and Sixty Five&quot;
Case 66: strPounds = strPounds & &quot; and Sixty Six&quot;
Case 67: strPounds = strPounds & &quot; and Sixty Seven&quot;
Case 68: strPounds = strPounds & &quot; and Sixty Eight&quot;
Case 69: strPounds = strPounds & &quot; and Sixty Nine&quot;
Case 70: strPounds = strPounds & &quot; and Seventy&quot;
Case 71: strPounds = strPounds & &quot; and Seventy One&quot;
Case 72: strPounds = strPounds & &quot; and Seventy Two&quot;
Case 73: strPounds = strPounds & &quot; and Seventy Three&quot;
Case 74: strPounds = strPounds & &quot; and Seventy Four&quot;
Case 75: strPounds = strPounds & &quot; and Seventy Five&quot;
Case 76: strPounds = strPounds & &quot; and Seventy Six&quot;
Case 77: strPounds = strPounds & &quot; and Seventy Seven&quot;
Case 78: strPounds = strPounds & &quot; and Seventy Eight&quot;
Case 79: strPounds = strPounds & &quot; and Seventy Nine&quot;
Case 80: strPounds = strPounds & &quot; and Eighty&quot;
Case 81: strPounds = strPounds & &quot; and Eighty One&quot;
Case 82: strPounds = strPounds & &quot; and Eighty Two&quot;
Case 83: strPounds = strPounds & &quot; and Eighty Three&quot;
Case 84: strPounds = strPounds & &quot; and Eighty Four&quot;
Case 85: strPounds = strPounds & &quot; and Eighty Five&quot;
Case 86: strPounds = strPounds & &quot; and Eighty Six&quot;
Case 87: strPounds = strPounds & &quot; and Eighty Seven&quot;
Case 88: strPounds = strPounds & &quot; and Eighty Eight&quot;
Case 89: strPounds = strPounds & &quot; and Eighty Nine&quot;
Case 90: strPounds = strPounds & &quot; and Ninety&quot;
Case 91: strPounds = strPounds & &quot; and Ninety One&quot;
Case 92: strPounds = strPounds & &quot; and Ninety Two&quot;
Case 93: strPounds = strPounds & &quot; and Ninety Three&quot;
Case 94: strPounds = strPounds & &quot; and Ninety Four&quot;
Case 95: strPounds = strPounds & &quot; and Ninety Five&quot;
Case 96: strPounds = strPounds & &quot; and Ninety Six&quot;
Case 97: strPounds = strPounds & &quot; and Ninety Seven&quot;
Case 98: strPounds = strPounds & &quot; and Ninety Eight&quot;
Case 99: strPounds = strPounds & &quot; and Ninety Nine&quot;
End Select

ConstructString:
Select Case strPart
Case &quot;hundreds&quot;
GetPoundString = strPounds

If Right(GetPoundString, 4) = &quot; and&quot; Then GetPoundString = Left(GetPoundString, Len(GetPoundString) - 4)

If Left(GetPoundString, 4) = &quot; and&quot; Then GetPoundString = Right(GetPoundString, Len(GetPoundString) - 4)


Case &quot;thousands&quot;
GetPoundString = strPounds & &quot; Thousand&quot;

If Right(GetPoundString, 4) = &quot; and&quot; Then GetPoundString = Left(GetPoundString, Len(GetPoundString) - 4)

If Left(GetPoundString, 4) = &quot; and&quot; Then GetPoundString = Right(GetPoundString, Len(GetPoundString) - 4)


Case &quot;millions&quot;
GetPoundString = strPounds & &quot; Million&quot;

If Right(GetPoundString, 4) = &quot; and&quot; Then GetPoundString = Left(GetPoundString, Len(GetPoundString) - 4)

If Left(GetPoundString, 4) = &quot; and&quot; Then GetPoundString = Right(GetPoundString, Len(GetPoundString) - 4)


Case &quot;billions&quot;
GetPoundString = strPounds & &quot; Billion&quot;

If Right(GetPoundString, 4) = &quot; and&quot; Then GetPoundString = Left(GetPoundString, Len(GetPoundString) - 4)

If Left(GetPoundString, 4) = &quot; and&quot; Then GetPoundString = Right(GetPoundString, Len(GetPoundString) - 4)


End Select
End Function
 
faq181-1740

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
At a first glance, I'd say the following line near the beginning of
Code:
GetPoundString
is part of the problem:

Code:
 If Right(Pounds, 2) = 0 Then ...

I can't see where
Code:
Pounds
is declared within GetPoundString - should this be
Code:
strPounds
or something?
[pc2]
 
... but you ALSO need to consider the 'grammer', as it is generally correct to insert 'AND' between the major and minor divisions of currency (as in between the Pound adn Pence? (e.g. for U.S. currency between Dollars and Cents). So even your example is incorrect?

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