Data/Read on TS 1000

Author(s): Bill Johnson
Pub Details: Time Designs Magazine v1 n3 (Volume 1, Issue 3)
Date: March/April 1985
Pages: 10-11

Many of you have discovered the ZX81 Computer does not have the DATA and READ commands in its vocabulary. These commands are the backbone of BASIC programming. You may have been unable to enter many programs written for other computers since you did not have the power of DATA and READ. The following only applies to the TS 1000, TS 1500 and Sinclair ZX81. The TS 2068 uses the DATA and READ commands.

First, let’s define the commands:

DATA- The DATA statement is a place to store values. Each value is seperated by a comma. The values entered into a DATA statement can be alphanumeric in nature.

READ- The READ statement inputs the values from the DATA statements, into variables defined in the program.

An example of the use of these commands follows:

   5 DIM A(5)
10 FOR I=1 TO 5
20 READ A(I)
30 NEXT I
40 DATA 1,2,3,4,5
100 FOR I=1 TO 5
110 PRINT A(I)
120 NEXT I

The above program would feed the values of the DATA statements to the variable A(I). After running this program, the values of A(I) would be 1,2,3,4, and 5.

So how can the DATA/READ routine be used on your TS?

The easiest way to explain is with an example. The program that follows will accomplish the same as the program above.

  10 LET A$="1,2,3,4,5,"
20 DIM A(5)
30 LET X=0
40 LET Y=1
50 FOR I=1 TO LEN A$
60 IF A$(I)="," THEN LET X=X+1
70 IF A$(I)="," THEN LET A(X)=VAL A$(Y TO I-1)
80 IF A$(I)="," THEN LET Y=I+1
90 NEXT I
100 FOR I=1 TO 5
110 PRINT A(I)
120 NEXT I

The lines 100 to 120 simply show you the results, they are not needed. We will now go line by line.

LINE 10: Acts like a DATA statement. You store your values here. It is important to end this statement with a “,” or the last value will not be input.

LINE 20 to 40: These lines set various variables.

LINE 50: This line sets a loop the length of A$. In this case the length is 10.

LINE 60 to 80: These lines all ask the question, “is the next item in A$ a “,”. The comma is used to seperate each value. If a comma is found, line 60 increments X by 1. X is used to set the value of A, the letter of the variable being read.

LINE 70: Stores the value into the variable A. Line 80 increments Y, which is the starting place for the next value.

As you can see the above program accomplishes the same as the DATA/READ commands. The above routine can also be used to read in ALPHA values, as follows:

  10 LET A$="A,B,C,D,E,"
20 DIM B$(5)
30 LET X=0
40 LET Y=1
50 FOR I=1 TO LEN A$
60 IF A$(I)="," THEN LET X=X+1
70 IF A$(I)="," THEN LET B$(X)=A$(Y TO I-1)
80 IF A$(I)="," THEN LET Y=Y+1
90 NEXT I
100 FOR I=1 TO 5
110 PRINT B$(I)
120 NEXT I

This program works the same way as our previous program. One limitation is that you can not use the “,” character in your values, or the program will consider this a stop point.

The above routines can be used to read values for various variables at the same time. For example, you may have a DATA statement: 1,A,2,B,3,C,4,D,5,E. You can read the values by combining the methods used above. I will leave this for you to do.

Bill Johnson is the president of WMJ DATA SYSTEMS, 4 Butterfly Dr., Hauppauge, NY, 11788. He also writes (and publishes) the QuarterS newsletter, and also writes for Computer Trader Magazine.

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