Classic Computer Magazine Archive COMPUTE! ISSUE 46 / MARCH 1984 / PAGE 156

PROGRAMMING THE TI

C. Regena

File Processing

I've received quite a few letters wondering about files on the TI-99/4A. Files on a computer can be compared to those ordinary big, gray file drawers. Each file is a drawer, and you can label your drawers. Each record is one of the file folders inside a drawer. On the computer your file cabinet can be either a cassette or a diskette.

You can read about file processing in the User's Reference Guide that comes with the computer (pages II-118 to II-136 for the TI-99/4A and pages 144 to 162 for the TI-99/4), so I won't repeat that information here. For some example programs, you can refer to "Color Computer General-Purpose Data Base" in COMPUTE! (May 1983).

If you prefer not to do your own programming, there are several business programs available for the TI, as well as some command modules which utilize file processing. Home Budget Management keeps personal finance records. Personal Record Keeping is a versatile module that helps you set up your own files and records for a small business.

A Spelling Drill

Let's get to an example. This "Spelling Quiz" program presents a drill for spelling words. In many schools, students are sent home with a list of words each Monday with instructions to practice, then a test is given on Friday. TI to the rescue! Enter the spelling words and save them on cassette. Let the computer conduct the drill.

Line 100 DIMensions or reserves space for 30 spelling words on the list. If you have more words, you can change this statement and lines 460—470 to handle more words. Lines 110–150 define graphics characters, and line 1630 draws a smiling face for a correct answer. Please feel free to add your own graphics. Lines 160–310 print the main menu screen of options. When you RUN the program, you have your choice of entering a new word list, editing the existing list, loading a list of previously saved words, saving the present list, reviewing the complete word list, actually performing the quiz, or ending the program.

The first time you RUN the program, you would press 1 to enter a word list, edit the list if necessary, then save the list on cassette for future use. Lines 320–370 contain the procedure that tells you when you try to access an empty list.

Enter The Number Of Words

When you enter a new word list, you are first asked how many words it will contain. This number, N, is unchanged throughout the program and is necessary for saving N items and for performing the quiz for N words. Lines 490–530 ask for the new words, and you type the words in one at a time, pressing ENTER after each word. When you have entered the right number of words, the program returns to the main menu screen.

The edit option is contained in lines 550–960. The complete word list is printed, then you can enter the word you want changed. Lines 640–660 compare the word you entered to the word list so the word can be replaced. If you prefer to delete the word, you can just press the ENTER key. Lines 730–770 adjust N and the positions of the other words if you delete a word.

Lines 1070–1150 save the list of words. The first time you use the program you would enter the words, then save the list for future use.

The OPEN statement is the crux of a file processing program. Line 1090 is OPEN #1:"CS1", INTERNAL, OUTPUT, FIXED which readies device number 1 (you can choose any number or even a variable name that corresponds to a number) labeled Cassette 1. The data file we create is for OUTPUT—we will be filing information on the tape. The format for this output is INTERNAL (versus DISPLAY) and FIXED (versus VARIABLE). This means that the computer will save the output in internal machine format rather than printable ASCII format, and that each record is FIXED at a certain length. Since I didn't specify a length, the computer will assume FIXED 64, or a record length of 64 characters.

Store The Program And Data Separately

To try this program, use one tape to store the actual program, then place a blank tape in the recorder to save this word list. This tape will be called the data tape. If you have diskettes you could call it a data diskette.

On the screen you will see cassette operating instructions. The PRINT #1 statement is used to put information on the tape, so line 1100 PRINT #1:N writes the number of words N on the tape. Lines 1110–1130 use PRINT #1 to record the words on the tape. When the data is being recorded you will hear a longer header tone, then a sort of dot-dot-dot sound, a little different sound than a regular program recording. CLOSE #1 closes the file and gives you instructions to turn off the recorder.

There are more efficient ways to save data (by combining strings, for example), but I used this method so it would be easier to understand. As you program, you will probably want to economize to save both memory and time.

The next time you run this program and want to use a previously saved list of words, press option 3, Load Previous List. Lines 970–1050 retrieve the data. The OPEN statement tells the computer what kind of information to expect. Line 990 OPEN #2:"CS1", INTERNAL, INPUT, FIXED opens device number 2—again, you can use any number here. For clarity I used #1 to save the data and #2 for retrieving the data, but you could use the same number for both processes. This statement matches line 1090 in the format of the data saved. Lines 1000–1030 are similar to the output lines. First N is read as input (INPUT #2, or input from device #2), then the words are read in. Line 1040 CLOSE #2 closes the file.

The Quiz Routine

Option 6 is to perform the spelling quiz. Lines 1250–1810 contain this procedure. The word list is in the W$ array, but an identical array T$ is defined for the quiz. A word is chosen in random order, and is printed on the screen. The student reads the word, then presses the ENTER key to erase it. The student then must type the word and press ENTER. If you prefer to have the word flash on the screen for a certain length of time, you can replace lines 1470–1480 with a delay loop or sound delay such as

1470 FOR D = 1 TO 800
1480 NEXT D

or

1470 CALL SOUND(1000, 9999, 30)
1480 CALL SOUND(1, 9999, 30)

If the student spells the word correctly, a smiling face is printed on the screen and TI plays an arpeggio. Correctly spelled words will not be chosen again, but a word that is missed will reappear later in the quiz.

F and FL are variables to keep track of words that are spelled incorrectly. SC is the score and is incremented only if the word is spelled correctly the first try.

Next month I'll have programs that show an easy way to set up a data file and print reports from the file.