Peter Hale, P.O. Box 8763, Boston, MA 02114
Computers should save time and effort. This program for the QL does both.
It’s purpose is to convert a number (entered as numerals) into an equivalent word string. E.G. input 111.11 and the program returns ONE HUNDRED ELEVEN AND 11/100.
The program handles numbers up to 999999.99 and converts them to the equivalent words.
Originally, the program was part of a check writing routine in ARCHIVE. Here, it is converted to SuperBASIC, while retaining the Archive syntax wherever possible.
Enter the listing. Start by entering the procedure sav at line 1400. As you enter the listing, occassionally save the work-in-progress by typing sav <ENTER> from the keyboard.
Run the program by lrun flp2_number <ENTER> or, if the program is in memory, type either run, start or ask_no, followed by <ENTER>.
Although there is limited application beyond check/receipt writing for this program, it is interesting to show the differences and similarities between SuperBASIC and ARCHIVE.
When entering the program in the edit mode of ARCHIVE, ignore lines 10 and 20. Enter each procedure (ignoring line numbers).
There are two other differences. Where the program has a line with a REMark in it, this is the ARCHIVE syntax to replace the SuperBASIC line immediately below it.
The other difference is universal. Wherever SuperBASIC uses the ampersand (&), ARCHIVE requires the plus sign (+).
To run the ARCHIVE version type run <ENTER>, then number <ENTER>. This auto-starts the program by searching out the procedure called start.
The SuperBASIC program version is ‘over-written’ to preserve the ARCHIVE syntax that will also operate in SuperBASIC.
For example, procedures no_1 (line 400), no_2 (line 600) and no_2a (line 800) could use SuperBASIC’s coercion by changing all occurance of nu$ to nu and removing the quotes from the numerals. Also, one line IF statements need not end with : END IF nor is it necessary to use the Keyword LET in SuperBASIC.
The program points up a weakness of coercion and SuperBASIC’s handling of floating point numbers in the procedure ask_no at line 100.
In Archive, the statement after the REMark in line 120 quickly converts numerals to text strings with an accuracy of up to sixteen (16) places.
SuperBASIC gets tangled coercing numbers of more than eight (8) significant places (the decimal point counts as a place). Thus, 100000.01 would not be accurate without the slicing and concatenation in line 130.
The Listing
10 ask_no: REMark not for ARCHIVE version
20 :
100 DEFine PROCedure ask_no
110 INPUT "Enter number as digits ";n
120 REMark let nn$=str(n,0,2)
130 n1$=INT(n):n2$=INT(((n-INT(n))+5E-3)*100):nn$=n1$&"."&n2$
140 convert:ask_no
160 :
170 DEFine PROCedure convert
180 REMark let dp=instr(nn$,"."): let nn=1
190 dp="." INSTR nn$:nn=1
200 IF dp=2:no_1: END IF
210 IF dp=3:no_2: END IF
220 IF dp=4:no_3: END IF
230 IF dp=5:no_4: END IF
240 IF dp=6:no_5: END IF
250 IF dp=7:no_6: END IF
260 LET txt$=" "&txt$&"AND "&nn$(dp+1 TO dp+2)&"/100"
270 IF LEN(txt$)<55
280 REMark let txt$=rept("*",54-len(txt$))+txt$
290 txt$=FILL$("*",54-LEN(txt$))&txt$
300 END IF
310 PRINT txt$
320 END DEFine convert
330 :
400 DEFine PROCedure no_1
410 LET nu$=nn$(nn): LET no1$=""
420 IF nu$="0" AND dp=2: LET no1$="ZERO ": END IF
430 IF nu$="1": LET no1$="ONE ": END IF
440 IF nu$="2": LET no1$="TWO ": END IF
450 IF nu$="3": LET no1$="THREE ": END IF
460 IF nu$="4": LET no1$="FOUR ": END IF
470 IF nu$="5": LET no1$="FIVE ": END IF
480 IF nu$="6": LET no1$="SIX ": END IF
490 IF nu$="7": LET no1$="SEVEN ": END IF
500 IF nu$="8": LET no1$="EIGHT ": END IF
510 IF nu$="9": LET no1$="NINE ": END IF
520 LET txt$=no1$
530 END DEFine no_1
540 :
600 DEFine PROCedure no_2
610 LET nu$=nn$(nn): LET no2$=""
620 IF nu$="1":no_2a: RETurn : END IF
630 IF nu$="2": LET no2$="TWENTY": END IF
640 IF nu$="3": LET no2$="THIRTY": END IF
650 IF nu$="4": LET no2$="FORTY": END IF
660 IF nu$="5": LET no2$="FIFTY": END IF
670 IF nu$="6": LET no2$="SIXTY": END IF
680 IF nu$="7": LET no2$="SEVENTY": END IF
690 IF nu$="8": LET no2$="EIGHTY": END IF
700 IF nu$="9": LET no2$="NINETY": END IF
710 LET nn=nn+1:no_1
720 IF nu$<>"0" AND nn$(nn-1)<>"0"
730 LET no2$=no2$&"-"
740 ELSE : LET no2$=no2$&" ": END IF
750 LET no2$=no2$&no1$: LET txt$=no2$
760 END DEFine no_2
770 :
800 DEFine PROCedure no_2a
810 LET nn=nn+1: LET nu$=nn$(nn)
820 IF nu$="0":LET no2$="TEN ":END IF
830 IF nu$="1":LET no2$="ELEVEN ":END IF
840 IF nu$="2":LET no2$="TWELVE ":END IF
850 IF nu$="3":LET no2$="THIRTEEN ":END IF
860 IF nu$="4":LET no2$="FOURTEEN ":END IF
870 IF nu$="5":LET no2$="FIFTEEN ":END IF
880 IF nu$="6":LET no2$="SIXTEEN ":END IF
890 IF nu$="7":LET no2$="SEVENTEEN ":END IF
900 IF nu$="8":LET no2$="EIGHTEEN ":END IF
910 IF nu$="9":LET no2$="NINETEEN ":END IF
920 LET txt$=no2$
930 END DEFine no_2a
940 :
1000 DEFine PROCedure no_3
1010 LET nu$=nn$(nn): LET no3$="":no_1
1020 IF no1$<>"": LET no3$=no1$&"HUNDRED "
1030 ELSE : LET no3$="": END IF
1040 LET nn=nn+1:no_2
1050 LET no3$=no3$&no2$: LET txt$=no3$
1060 END DEFine no_3
1070 :
1100 DEFine PROCedure no_4
1110 LET nu$=nn$(nn):no_1
1120 LET no4$=no1$&"THOUSAND "
1130 LET nn=nn+1:no_3
1140 LET no4$=no4$&no3$: LET txt$=no4$
1150 END DEFine no_4
1160 :
1200 DEFine PROCedure no_5
1210 LET nu$=nn$(nn):no_2
1220 LET no5$=no2$&"THOUSAND "
1230 LET nn=nn+1:no_3
1240 LET no5$=no5$&no3$: LET txt$=no5$
1250 END DEFine no_5
1260 :
1300 DEFine PROCedure no_6
1310 LET nu$=nn$(nn):no_3
1320 LET no6$=txt$&"THOUSAND "
1330 LET nn=nn+1:no_3
1340 LET no6$=no6$&no3$: LET txt$=no6$
1350 END DEFine no_6
1360 :
1400 DEFine PROCedure sav
1410 REMark save "flp2_number"
1420 DELETE "flp2_number": SAVE "flp2_number"
1430 END DEFine sav
1440 :
1450 DEFine PROCedure start
1460 ask_no
1470 END DEFine start
Note: This article is prepared on a 24 pin Panasonic KX-1124 printer in letter quality Courier font, micron (15 char/inch) pitch.
It requires only minor adjustments to Epson control codes through the install_bas program to access the vast majority of the features of this printer under Quill.
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.