Here tabad is the code far turning numbers into text when writting checks. Hope this helps.
Injoy!
Charles
Public 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"
stResult = "and " & Format((curValue - Int(curValue)) * 100, "00" & "/100"
stTemp = CStr(Int(curValue))
For i = Len(stTemp) To 1 Step -1
nNumber = Val(Mid(stTemp, i, 1))
'Check the position(column) of this digi
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 hyp
'Check if the digit has a value other th
'digit to see if it has a value other th
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
Sincerely,
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.