Microsoft Office Tutorials and References
In Depth Information
Using Custom Functions
Listing 3-1 (continued)
EngNum(20) = “Twenty”
EngNum(30) = “Thirty”
EngNum(40) = “Forty”
EngNum(50) = “Fifty”
EngNum(60) = “Sixty”
EngNum(70) = “Seventy”
EngNum(80) = “Eighty”
EngNum(90) = “Ninety”
‘** Copy amount passed to a string with leading zeroes.
strNum = Format(AmountPassed, “000000000.00”)
‘** Put last two digits in Pennies variable for later use.
Pennies = Mid(strNum, 11, 2)
‘Set starting values for some local variables.
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 “
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

Search JabSto ::

Custom Search