Conversion of Data in BASIC on the Z88

See all articles from CATS v6 n8
Author(s): Peter van Dijk
Publication: CATS Newsletter
Pub Details: CATS v6 n8 (Volume 6, Issue 8)
Date: December 1988
Pages: 6

If numerical data is printed from a BASIC program to a file, the data is tokenised and cannot be read with a wordprocessor. If you want to have readable data (ASCII), you have to print the data to a file, using PRINT#c,STR$(x) where x is a numerical variable, The file created with this method however, will be larger and loads a lot slower than a tokenised file. The ASCII file on the other hand can be sent through the SER port. The following program changes a tokenised file into an ASCII file that can be read and modified with a wordprocessor. The opposite conversion can also be done

10 CLS:PRINT TAB(20,2);"1) TO TEXT FILE"
20 INPUT TAB(20);"2) TO CODED FILE";inp%
30 INPUT TAB(20);"FILE N AME ";inp$
40 IF inp%=1 in$=inp$:out$=in$+".txt"
50 IF inp%=2 in$=inp$+".txt":out$=inp$
60 c%=OPENIN(in$):d%=OPENOUT(out$)
70 IF inp%=2 GOTO 120
80 REPEAT
90 INPUT#c%,in%:PRINT#d%,STR$(in%)
100 PRINT TAB(40,6);in%
110 UNTIL EOF#c%
120 GOTO 160
130 REPEAT
140 INPUT#c%,in$:out%=VAL(in$):PRINT#d%,out%
150 PRINT TAB(40,6);out%
160 UNTIL EOF#c%
170 CLOSE#c%:CLOSE#d%:END

Lines 100 and 150 print the data to the screen so that you can see that something is happening. They can be removed without affecting the program. When converting to ASCII, the extension .txt is added to the file name by the program. When using the program in the opposite direction the extension does not have to be input.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.