BBS: Inland Empire Archive Date: 09-06-92 (15:27) Number: 323 From: QUINN TYLER JACKSON Refer#: NONE To: ALL Recvd: NO Subj: Longhand.Bas Conf: (2) Quik_Bas
' Here is a FUNCTION someone may find useful for printing out cheques. ' For example, 234 would come out 'two hundred and thirty four' as ' a longhand string ' Use it in good health! ' Quinn DECLARE FUNCTION LongHand$ (Number AS INTEGER) ' This little test program includes a useful FUNCTION that will convert ' any integer between -9999 and 9999 into 'longhand'. The FIRST call to ' this function initializes the DATA array. Any subsequent call will ' execute more efficiently, since the STATIC declaration will preserve the ' data in the array for later use. ' ' This little ditty released into the Public Domain ' By Quinn Tyler Jackson 06 SEP 92. ' Declare logical constants CONST TRUE = -1 CONST FALSE = NOT TRUE ' Test Run ' The first call to the function takes a bit longer PRINT LongHand(-4678) ' than the second..... PRINT LongHand(9999) END ' This DATA is required by the function. LongHandData: DATA one,two,three,four,five,six,seven,eight,nine,ten DATA eleven,twelve,thirteen,fourteen,fifteen,sixteen DATA seventeen,eighteen,nineteen DATA twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety DEFINT A-Z FUNCTION LongHand$ (Number AS INTEGER) STATIC ' Do NOT remove the STATIC declaration if you wish this ' FUNCTION to run at its most efficient ' Only initialize the data array if this is the first time this ' function is called IF NOT BeenHereBefore THEN DIM Num$(27) RESTORE LongHandData FOR i = 1 TO 27 READ Num$(i) NEXT i BeenHereBefore = TRUE END IF IF Number < 0 THEN temp$ = "negative " Number = ABS(Number) ' Thousands position IF Number >= 1000 THEN temp$ = temp$ + Num$(Number \ 1000) + " thousand " Number = Number MOD 1000 END IF ' Hundreds position IF Number >= 100 THEN temp$ = temp$ + Num$(Number \ 100) + " hundred " Number = Number MOD 100 END IF ' Add the 'and' if necessary IF Number > 0 AND temp$ <> "" AND LEFT$(temp$, 3) <> "neg" THEN temp$ = temp$ + "and " END IF ' Special tens position IF Number > 20 THEN temp$ = temp$ + Num$(Number \ 10 + 18) + " " Number = Number MOD 10 END IF ' Ones positions IF Number >= 1 AND Number <= 20 THEN temp$ = temp$ + Num$(Number) END IF LongHand$ = temp$ temp$ = "" END FUNCTION ... Netmail corrupts, routed netmail corrupts absolutely. ___ Blue Wave/QWK v2.10 --- Maximus/2 2.01wb * Origin: The Nibble's Roost, Richmond BC Canada 604-244-8009 (1:153/918)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET