(or, How to convert decimal digits to printable strings)
I originally wrote the following program for a customer in Micro-Soft’s Extended Disk Basic. It does not transfer to Timex Basic as well as I had hoped but will perhaps be of use to you.
I have often said that I much prefer the method Sinclair used for string handling over MicroSoft’s however, this time I found a reason to like MicroSoft Basic.
You will note that the strings are DIMensioned to the length of the longest required string of the group. MicroSoft Basic does not require the second parameter therefore, the strings can be different lengths within the same array. I chose to eliminate some of the additional spaces this creates by use of the backspace character (CHR$ 8). This fix will not work on some printers and may require a loop to slice off the trailing spaces but, I will leave that to you.
The work is done in lines 110 to 250, with a companion subroutine at line 500. It would normally be called as a subroutine, from within your program, with the variable C$ containing a string of printable digits.
The first step is to ensure the number is padded-out to two decimal places, which is why it is handled as a string. Then all leading 0’s and spaces are removed. There is no error checking done for non-digits as the original program ensured the data was checked prior to placing it on the disk.
I converted it to Timex Basic as lots of individual lines in order to allow compatibility with the TS1000. 2068 users will be able to compact it greatly.
Also, as it stands the program will not properly write any amount that exceeds 9,999,999.99. You can of course change this.
The program will be of interest to you if you running a business that writes a lot of checks. I have retained the copyright as it is part of another program however, you are free to modify and use it for your own use.
1 REM The Check Writer
2 REM 1987 by Syd Wyncoop
3 REM
4 LET getdigit=500
10 REM Set-up check writing
strings
11 REM Set-up One$
12 DIM O$(10,5)
13 LET O$(1) ="VOID*"
14 LET O$(2) ="One "+CHR$ 8
15 LET O$(3) ="Two "+CHR$ 8
16 LET O$(4) ="Three"
17 LET O$(5) ="Four"
18 LET O$(6) ="Five"
19 LET O$(7) ="Six "+CHR$ 8
20 LET O$(8) ="Seven"
21 LET O$(9) ="Eight"
22 LET O$(10)="Nine"
23 REM Set-up Ten$
24 DIM T$(10,8)
25 LET T$(1) ="**VOID**"
26 LET T$(2) ="**VOID**"
27 LET T$(3) =" Twenty"
28 LET T$(4) =" Thirty"
29 LET T$(5) =" Fourty"
30 LET T$(6) =" Fifty "+CHR$ 8
31 LET T$(7) =" Sixty "+CHR$ 8
32 LET T$(8) =" Seventy"
33 LET T$(9) =" Eighty"
34 LET T$(10)=" Ninety"
35 REM Set-up Teen$
36 DIM N$(10,10)
37 LET N$(1) =" Ten "+CHR$ 8+CHR$ 8
38 LET N$(2) =" Eleven "+CHR$ 8
39 LET N$(3) =" Twelve "+CHR$ 8
40 LET N$(4) =" Thirteen"
41 LET N$(5) =" Fourteen"
42 LET N$(6) =" Fifteen "+CHR$ 8
43 LET N$(7) =" Sixteen "+CHR$ 8
44 LET N$(8) =" Seventeen"
45 LET N$(9) =" Eighteen"
46 LET N$(10)=" Nineteen"
99 REM
100 REM Test Program
101 INPUT "Enter the number to write"' LINE C$
102 GO SUB 110
103 PRINT K$
104 GO TO 100
110 REM Enter the subroutine
with C$=number to write
111 REM Pad-out number to two
decimal places and make
sure no leading spaces
or leading zeroes
112 LET A$=C$+".00"
113 IF A$(1)=" " THEN LET A$=A$(2 TO ): GO TO 113
119 LET c=1
120 FOR i=1 TO LEN A$
121 IF A$(i)="." THEN GO TO 124
122 LET c=c+1
123 NEXT i
124 LET c=c+2
125 LET A$=A$( TO c)
126 IF A$(1)="0" THEN LET A$=A$(2 TO ): GO TO 126
127 LET c=LEN A$: IF A$(c)="." THEN LET A$(c)="0"
130 REM Convert to string
131 LET c=LEN A$
132 LET K$="****"
133 LET flag=0
134 IF c=3 THEN GO TO 220
135 IF c<10 THEN GO TO 140
136 GO SUB getdigit: LET K$=O$(a)+" Million, "
140 IF c<9 THEN GO TO 150
141 GO SUB getdigit: IF a=1 THEN GO TO 150
142 LET K$=K$+O$(a)+" Hundred": LET flag=1
150 IF c<8 THEN GO TO 160
151 GO SUB getdigit: IF a=1 THEN LET K$=K$+" ": GO TO 160
152 IF a=2 THEN GO SUB getdigit: LET K$=K$+N$(a): LET flag=1: GO TO 170
153 LET K$=K$+T$(a): LET flag=1
154 GO SUB getdigit: IF a=1 THEN GO TO 170
155 LET K$=K$+"-"+O$(a): LET flag=1: GO TO 170
160 IF c<7 THEN GO TO 170
161 GO SUB getdigit: IF a=1 THEN GO TO 170
162 LET K$=K$+O$(a): LET flag=1
170 IF flag=1 THEN LET K$=K$+" Thousand, ": LET flag=0
171 IF c<6 THEN GO TO 180
172 GO SUB getdigit: IF a=1 THEN GO TO 180
173 LET K$=K$+O$(a)+" Hundred": LET flag=1
180 IF c<5 THEN GO TO 190
181 GO SUB getdigit: IF a=1 AND flag=1 THEN LET K$=K$+" ": LET flag=0
182 IF a=1 THEN GO TO 190
183 IF a=2 THEN GO SUB getdigit: LET K$=K$+N$(a): GO TO 210
184 LET K$=K$+T$(a)
185 GO SUB getdigit: IF a=1 THEN GO TO 210
186 LET K$=K$+"-"+O$(a): GO TO 210
190 IF c<4 THEN GO TO 210
191 GO SUB getdigit: IF a=1 THEN GO TO 210
192 LET K$=K$+O$(a)
210 IF c<=3 THEN GO TO 220
211 LET K$=K$+" AND "
220 LET A$=A$(LEN A$-1 TO )
221 IF A$="00" THEN LET K$=K$+"No": GO TO 240
223 GO SUB getdigit: LET K$=K$+STR$ (a-1)
230 LET K$=K$+A$
240 LET K$=K$+"/100****"
241 REM most checks have the
word 'dollars' printed
on them but, you could
add it here if needed
as follows:
241 LET K$=K$+" Dollars"
250 RETURN
500 REM getdigit
501 LET a=VAL A$(1)+1
502 LET A$=A$(2 TO )
503 RETURN
9989 STOP
9990 MOVE "Checks.bas",: CAT "",
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.