Hello,
Try the programming below should produce the correct results for you. It is looking like one of the If statements needed to be inside of another If statement and not right after it. After making this change I tried it with the number you gave and it appears to be correct.
-Ray
var vAmount as String
var vWords as String
var Dollars as String
var Cents as String
var Chunk as String
var leftdigit as Int
var rightdigit as Int
var digits as Int
var BigOnes as array[9] of String
var SmallOnes as array[19] of String
Subroutine ParseChunk()
digits = @Left(Chunk, 1)
If digits > 0 Then
{
vWords = vWords + " " + SmallOnes[digits] + " Hundred"
}
digits = @Mid(Chunk, 2, 2)
If digits > 19 Then
{
leftdigit = @Mid(Chunk, 2, 1)
rightdigit = @Mid(Chunk, 3, 1)
vWords = vWords + " " + BigOnes[leftdigit]
If rightdigit > 0 Then
{
vWords = vWords + " " + SmallOnes[rightdigit]
}
}
Else
{
If (digits <= 19) and (digits > 0) Then
{
vWords = vWords + " " + SmallOnes[digits]
}
}
End Subroutine
vAmount = Amount
If (vAmount <> "0") And (@Int(vAmount) <= 999999) And (vAmount > 0) Then
{
If @Instr(vAmount, ".") = 0 Then
{
vAmount = vAmount + ".0000"
}
// Fill the two arrays.
BigOnes[1] = "Ten"
BigOnes[2] = "Twenty"
BigOnes[3] = "Thirty"
BigOnes[4] = "Forty"
BigOnes[5] = "Fifty"
BigOnes[6] = "Sixty"
BigOnes[7] = "Seventy"
BigOnes[8] = "Eighty"
BigOnes[9] = "Ninety"
SmallOnes[1] = "One"
SmallOnes[2] = "Two"
SmallOnes[3] = "Three"
SmallOnes[4] = "Four"
SmallOnes[5] = "Five"
SmallOnes[6] = "Six"
SmallOnes[7] = "Seven"
SmallOnes[8] = "Eight"
SmallOnes[9] = "Nine"
SmallOnes[10] = "Ten"
SmallOnes[11] = "Eleven"
SmallOnes[12] = "Twelve"
SmallOnes[13] = "Thirteen"
SmallOnes[14] = "Fourteen"
SmallOnes[15] = "Fifteen"
SmallOnes[16] = "Sixteen"
SmallOnes[17] = "Seventeen"
SmallOnes[18] = "Eighteen"
SmallOnes[19] = "Nineteen"
// Separate the dollars from the cents
// Format incoming number to ensure 6 digits
// to the left of the decimal & 2 to the right
Dollars = @Left(vAmount, @Instr(vAmount, ".") - 1)
Dollars = @Right("000000" + Dollars, 6)
Cents = @Right(vAmount, 4)
Cents = @Left(Cents, 2)
// Separate the dollars into chunks
If @Int(Dollars) = 0 Then
{
vWords = "Zero"
}
Else
{
// First do the thousands
Chunk = @Left(Dollars, 3)
If @Int(Chunk) > 0 Then
{
ParseChunk()
vWords = vWords + " Thousand"
}
// Do the rest of the dollars
Chunk = @Right(Dollars, 3)
If @Int(Chunk) > 0 Then
{
ParseChunk()
}
}
// Concatenate the cents and display
// If Cents = 0 Then
// Cents = "00"
vWords = vWords + " and " + Cents + "/100"
// Optionally add asterisks to pad out the string
If @Len(vWords) < 65 Then
{
vWords = vWords + @Text(72 - @Len(vWords), "*")
}
Words = vWords
}
Else
{
@MsgBox("Amount must be more than 0 and less than 1,000,000.", "","")
}