ZX-81/TS-1000 Data Management
George W. Miller
The user of the Timex-Sindair computer can store and work with data files, even though some commands for handling data are missing. This program can be easily adapted for other kinds of data management too.
There are no commands for DATA, READ, RESTORE, RIGHTS, LEFTS, and MID$ in Sinclair BASIC. However, there are ways of getting around this lack of data management commands.
The easiest way to store data is in string arrays, using a FOR/NEXT loop to load the array, and using substrings to retrieve the information.
The program here is a file of addresses, but you could use the same method to keep track of membership rosters, records for an amateur radio station, a reference index for keeping track of interesting magazine articles or recipes. I do all these things with it.
The data is saved on tape by the SAVE command and is loaded into the computer for use. However, you don't start the program with RUN.
The RUN command clears all variables, so all that's left is a program with no data. If you do forget and hit RUN, you'll have to stop and reload your program from the tape.
Handy Address File
The "Addfile" program is set up to store 100 names, addresses, and phone numbers, and to search for information by either name or city.
If you have a printer, just add another function, LPRINT, and the appropriate subroutine, and you can have a printout of any addresses you desire.
Type the program into RAM. Try using inverse video on some of the headings to dress up your program a bit.
Notice lines 10-17, the dimension statements. Line 13 sets up an array named N$ which is a two-dimensional array with 100 subscripts for N$, each 30 characters in length. Or you may find it easier to visualize as a block 100 lines long and 30 characters wide in which information can be stored.
In lines 40-46, I'm just being fancy. The Timex-Sinclair Computer can look for headings to execute commands as well as looking the more common way, by checking line numbers.
CHANGE = 500 is setting up a change for later; the correction sub-program begins at line 500. Likewise for ENTER = 1000, LIST = 1500, and SEARCH = 2000.
In typing in my program menu, I used inverse letters for my commands. Note that for the stop in line 63, the shifted A is not spelled out.
In the SEARCH routine, we are using substrings to compare the characters stored in the file to the information supplied from the keyboard.
If you don't enter the FAST command, the program will run very slowly as the computer searches sequentially through its memory for the information.
After typing in the program, you're ready to RUN it; this is the only time you'll use the command RUN, unless you want to clear the variables to start a new file.
After entering RUN, the computer sets aside space in RAM for the variables, and will initialize the FOR/NEXT loops.
The screen will display the title block, then go to the menu. Enter "E" to go into the Entry Mode.
The program will display the last number used; this number is stored in memory for use in the change mode.
Caution: Narrow String Arrays
Follow the program prompts to enter data into the string arrays. Note that the strings for name and address are only 30 characters wide, so some abbreviation may be necessary. Any extra characters entered will be ignored.
The array for the phone number is 12 characters wide, so an area code can be included.
Zip code, Z$, is only five characters wide. If the postal service goes to the expanded zip code, you'll have to re-dimension this array to store the extra digits.
In line 1115, the computer will ask if you want to make another entry. By answering "N", you will exit the loop, but the number is stored in line 47 by allowing N = L.
Whenever you return to the Entry Mode, the program will pick up at the number where you stopped and then continue to number 100, when the "memory full" message will be displayed.
After entering "Y", you will drop to line 1140, and go back to the start of the loop.
If you notice an error in your data, complete the entry of information called for in the prompts by entering anything; then, when asked for another entry, enter "N". The screen will clear, and the program menu will be displayed.
Enter "C" and go into the Change Mode, which begins with line 500.
The display will ask for the number to change and, after receiving the number, will display the data on file at the top of the screen. Follow the instructions from the computer to reenter your data. Note that you will have to enter all the information for that entry.
After you complete the corrections, the screen will clear, and the menu will be displayed.
Choose Any Function
Now, you can enter "E" and continue making entries to your file, or enter any other function displayed on the menu.
If you'd like to scan your file, enter "L" for list. Be careful – this is the letter "L", not the function list. If you're like me, you'll want to keep entering the function "LIST", which will print as a "K"; the computer will ignore this error and ask for another command.
The screen will now begin to scroll up, displaying the contents of your file. After printing the last data in the file, the display will pause several seconds, and then the display will begin to scroll off, one line at a time. This is annoying, but I couldn't find any way around it after scrolling a long list.
After the screen is cleared, the display will go blank for several seconds, then return to the program menu.
Here's the most interesting feature of the program. Enter "S" to start the Search Mode.
The computer will ask if you'd like to search for a name or for all the names in a given city.
If you're looking for an address, enter the appropriate command from the prompts.
Make sure the spelling is correct. It may be necessary to try several variations if you're not sure of the spelling because the computer will only give you the information stored in the memory if there is a perfect match. For instance, if the name you're looking for is "John Smith" and the computer has "Mr. and Mrs. John R. Smith" stored in memory, the display will indicate "Name Not Found".
If you want a listing of all the names and addresses in your file from a given area, enter the CITY SEARCH command, and the computer will print a list of all names in memory in that city.
Again, the list must be exact for the computer to print it, so be consistent with your entries. Don't list Penna. one time and Pa. the next.
If there are more names and addresses than can be displayed on the screen, the program will fill the screen and return the error code 55/2041. After using the displayed information, enter CONT to clear the screen and continue with the listing of data from the memory.
By using subscripts in the arrays, the computer is comparing each character in the key arrays to find the matches. This is why you must be very careful with the data you input to get anything useful in output. If the program fails to run properly, check your input.
In the search mode, the command PAUSE 30000 is used. This holds the display for about nine minutes to give you a chance to use the displayed data. Since you will seldom need nine minutes, just press ENTER when you're finished, and the program menu will be displayed.
After working on your file, return to the program menu, and enter the function STOP (shifted A). The cursor will disappear and an error message will be displayed to indicate a break in the program.
All the data you entered is now stored in the string arrays. Enter LIST, get a display of the program listing, and SAVE in the usual manner; enter SAVE "ADDFILE".
This program takes about seven minutes to LOAD or SAVE, so don't be concerned about the time the screen is flickering.
It is probably worthwhile to save the program twice, for insurance against missing bytes. If the first program fails to load, the second follows immediately; the computer will pick it up.
Then use your file, LOADing in the normal way. However, after getting the 0/0 report, enter LIST, or just GOTO 35. This keeps all your data stored in the variables. If you pressed RUN and ENTER, you'll have to reload the tape to retrieve your data. From the program listing, enter GOTO 35 as shown in line 8.
If you'd like to make changes in the program for other uses, just change the title in the title subroutine to one more appropriate, and change the PRINT statements in the program prompts.
If your file is filled and you need to start a second file, just load the program into RAM, enter RUN to clear the variables, and start a new file, holding your old file on the cassette tape. Change the title blocks to indicate that two files exist, and remember that the information you don't have in one file may exist in the other.
Note: All underlined characters should be entered in inverse video.