Hi Ken
I couldn't try Bob's solution as there's an un-dimensioned variable
called
"Count" in there and I don't know what it refers to.
I think it was me, not Bob, who posted the revision to the Spell number
code.
The copy of Spellnumber I found on Google did have Count defined.
The code loops through the GetHundreds routine a number of times,
dependant upon the size of the figure being converted.
The first time through, I thought it would be more correct to express
the value £123,056
as
One Hundred and Twenty Three Thousand No Hundreds and Fifty Six Pounds
and No Pence
rather than
One Hundred and Twenty Three Thousand and Fifty Six Pounds and No Pence
Whereas, I didn't think it would be right in the case of £23,056 to have
No Hundreds and Twenty Three Thousand No Hundreds and Fifty Six Pounds
and No Pence.
(NB for Pounds read Dollars in your case)
It's up to you, Ken.
If you don't want the No Hundreds bit, just comment out the 3 lines in
the section of code I posted. and just leave the only amendment as being
the addition of the word "and" after "Hundreds" in the original code.
For the sake of completeness, I enclose the complete sub-function from
within the Spellnumber code that does the conversion of hundreds
(The code is not mine originally, I do not know the source, I merely
amended what I found with a Google search following your initial
posting).
'*******************************************
' Converts a number from 100-999 into text *
'*******************************************
Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3) 'Convert the hundreds
place
' If Mid(MyNumber, 1, 1) = "0" And Count < 2 Then
' Result = GetDigit(Mid(MyNumber, 1, 1)) & " No Hundreds and "
' End If
If Mid(MyNumber, 1, 1) <> "0" Then
Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred and "
End If
'Convert the tens and ones place
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(MyNumber, 2))
Else
Result = Result & GetDigit(Mid(MyNumber, 3))
End If
GetHundreds = Result
End Function
And the part of the code which Dims Count (incorrectly, it should be Dim
Count as Integer) and uses it
'****************' Main Function *'****************
Function SpellNumber(ByVal MyNumber)
Dim Pounds, Pence, Temp
Dim DecimalPlace, Count
ReDim place(9) As String
place(2) = " Thousand "
place(3) = " Million "
place(4) = " Billion "
place(5) = " Trillion " ' String representation of amount
MyNumber = Trim(Str(MyNumber)) ' Position of decimal place 0 if
none
DecimalPlace = InStr(MyNumber, ".")
'Convert Pence and set MyNumber to Pound amount
If DecimalPlace > 0 Then
Pence = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Pounds = Temp & place(Count) & Pounds
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
........
............
I hope this clears things up and allows you to make the modification
accordingly.