Private Function CurrencyToText(curValue As Currency) As String
Static Ones(10) As String
Static Teens(10) As String
Static Tens(10) As String
Static Thousands(3) As String
Dim i As Integer, nPosition As Integer
Dim nNumber As Integer, nStars As Integer
Dim bZeroValue As Boolean
Dim stResult As String, stTemp As String, stStars As String
Dim stBuffer As String
If curValue > 999999.99 Then
MsgBox "The limit of this Function is 999999.99", vbExclamation, "Danger, Danger Will Robinson"
Exit Function
End If
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"
'Set the cents portion of the string
'stResult = "and " & Format((curValue - Int(curValue)) * 100, "00"

'Convert the dollar portion to a string
stTemp = CStr(Int(curValue))
'parse through string(Dollar ammount)
For i = Len(stTemp) To 1 Step -1
'Grab the value of this digit
nNumber = Val(Mid(stTemp, i, 1))
'Check the position(column) of this digit
'Ones, Tens, or Hundereds
nPosition = (Len(stTemp) - i) + 1
Select Case (nPosition Mod 3)
Case 1 'Ones position
bZeroValue = False
If i = 1 Then
stBuffer = Ones(nNumber) & " "
ElseIf Mid(stTemp, i - 1, 1) = "1" Then
stBuffer = Teens(nNumber) & " "
i = i - 1 'Skip tens position
ElseIf nNumber > 0 Then
stBuffer = Ones(nNumber) & " "
Else
bZeroValue = True
If i > 1 Then
If Mid(stTemp, i - 1, 1) <> "0" Then
bZeroValue = False
End If
End If
If i > 2 Then
If Mid(stTemp, i - 2, 1) <> "0" Then
bZeroValue = False
End If
End If
stBuffer = ""
End If
If bZeroValue = False And nPosition > 1 Then
stBuffer = stBuffer & Thousands(nPosition / 3) & " "
End If
stResult = stBuffer & stResult
Case 2 'Tens position
'Numbers like twenty-five need to be hyphenated. So......
'Check if the digit has a value other than 0 AND check the next
'digit to see if it has a value other than 0
'if both are true add the hyphen
If nNumber > 0 And Val(Mid(stTemp, i + 1, 1)) = 0 Then
stResult = Tens(nNumber) & " " & stResult
ElseIf nNumber > 0 And Val(Mid(stTemp, i + 1, 1)) > 0 Then
stResult = Tens(nNumber) & "-" & stResult
End If
Case 0 'Hundreds position
If nNumber > 0 Then
stResult = Ones(nNumber) & " hundred " & stResult
End If
End Select
Next i
If Len(stResult) > 0 Then
stResult = UCase(Left(stResult, 1)) & Mid(stResult, 2)
End If
nStars = 125 - Len(stResult)
For i = 0 To nStars
stStars = stStars
Next
CurrencyToText = stResult & " " & stStars
End Function
Two textbox (text1 with the value )
Private Sub Command1_Click()
CurrencyToText (Text1)
Text2 = CurrencyToText(Text1)
End Sub
Eric De Decker
vbg.be@vbgroup.nl
Licence And Copy Protection AxtiveX
Source CodeBook for the programmer