After getting advice some time ago, I came up with the following
subroutine which uses two globals "[email protected]@" to go into the sub with
and "figstring$" comes out of the sub with the amount in words.
It is shorter than other routines but it works okay for me. Note
that it will only go up to $99,999.99 because that was all I needed
when I wrote it. You will also note it has an offensive "and" in
it which is the way we say it in Australia but does not appeal to
some people in the USA.
Regards,
Brian
Code:
' ----------------------------------------------- SUB INTOWORDS([email protected]@) LOCAL a$(), aline$ DIM a$(100) figstring$ = "" a$(1) = "ONE" a$(2) = "TWO" a$(3) = "THREE" a$(4) = "FOUR" a$(5) = "FIVE" a$(6) = "SIX" a$(7) = "SEVEN" a$(8) = "EIGHT" a$(9) = "NINE" a$(10) = "TEN" a$(11) = "ELEVEN" a$(12) = "TWELVE" a$(13) = "THIRTEEN" a$(14) = "FOURTEEN" a$(15) = "FIFTEEN" a$(16) = "SIXTEEN" a$(17) = "SEVENTEEN" a$(18) = "EIGHTEEN" a$(19) = "NINETEEN" a$(20) = "TWENTY" a$(30) = "THIRTY" a$(40) = "FORTY" a$(50) = "FIFTY" a$(60) = "SIXTY" a$(70) = "SEVENTY" a$(80) = "EIGHTY" a$(90) = "NINETY" IF [email protected]@ > 0 THEN aline$=FORMAT$([email protected]@,"#####.##") [email protected]@ = VAL(MID$(aline$,1,2)) IF [email protected]@ > 0 THEN IF [email protected]@ < 20 THEN figstring$ = a$([email protected]@) & " " & "THOUSAND " ELSE [email protected]@ = VAL(MID$(aline$,1,1)) figstring$ = a$([email protected]@*10) & " " [email protected]@ = VAL(MID$(aline$,2,1)) IF [email protected]@ > 0 THEN figstring$ = figstring$ & a$([email protected]@) END IF figstring$ = figstring$ & " THOUSAND " END IF END IF [email protected]@ = VAL(MID$(aline$,3,1)) IF [email protected]@ > 0 THEN figstring$ = figstring$ & a$([email protected]@) & " HUNDRED " END IF [email protected]@ = VAL(MID$(aline$,4,2)) IF [email protected]@ > 0 THEN IF figstring$ > "" THEN figstring$ = figstring$ & "AND " END IF IF [email protected]@ < 20 THEN figstring$ = figstring$ & a$([email protected]@) & " " ELSE [email protected]@ = VAL(MID$(aline$,4,1)) figstring$ = figstring$ & a$([email protected]@*10) & " " [email protected]@ = VAL(MID$(aline$,5,1)) IF [email protected]@ > 0 THEN figstring$ = figstring$ & a$([email protected]@) & " " END IF END IF END IF figstring$ = figstring$ & "DOLLARS" [email protected]@ = VAL(MID$(aline$, 7, 2)) IF [email protected]@ > 0 THEN figstring$ = figstring$ & " AND " IF [email protected]@ < 20 THEN figstring$ = figstring$ & a$([email protected]@) & "CENTS" ELSE [email protected]@ = VAL(MID$(aline$, 7, 1)) figstring$ = figstring$ & a$([email protected]@*10) & " " [email protected]@ = VAL(MID$(aline$, 8, 1)) IF [email protected]@ > 0 THEN figstring$ = figstring$ & a$([email protected]@) & " " END IF figstring$ = figstring$ & " CENTS" END IF ELSE figstring$ = figstring$ & " EXACTLY" END IF figstring$ = LCASE$(figstring$) REPLACE " " WITH " " IN figstring$ MID$(figstring$,1,1) = UCASE$(MID$(figstring$,1,1)) END IF END SUB ' -----------------------------------------------
Leave a comment: