Classic Computer Magazine Archive COMPUTE! ISSUE 49 / JUNE 1984 / PAGE 112

Commodore Information Handyman

F. Joseph Walker

"Information Handyman" demonstrates some practical uses of data files, and includes a program to keep track of your checking account. Originally written for the VIC with Datassette, the program can also be used on the Commodore 64 and PET/CBM, and can be modified for use with disk.

When data is needed during a program, it is often input from the keyboard or read from DATA statements within the program. Such data is program-dependent, part of the program itself, and therefore not available to other programs. But programs can also use data stored in files. A data file contains information, alphabetic or numeric, that is completely separate from a program. (It's program-independent.) Program-independent files make it possible to share information among several different programs.

Let's say you have computerized your Christmas card list and put the information into a data file. The file contains the names, addresses, cities, states, and zip codes of individuals to whom you will send cards. You can create various programs to manipulate the same information in different ways. For example, you could write one program to sort the names alphabetically, another program to sort by state or zip code, and still another program to search for the mailing information when given a name. You could write an editing program to add, change, or delete names from the list.

Creating A Data File

Let's look at how a data file is created. The general steps are:

  1. OPEN a file for data entry.
  2. Collect the information to be stored in the file.
  3. Write the data to the file.
  4. CLOSE the file.

"Information Handyman" illustrates this process by setting up a data file on cassette tape to maintain records of your checking account. Once you understand how the program works, you can easily modify it to handle similar types of information.

Changing Information In The File

Here is some information about the program's operation. Suppose an error was made in an entry when a file was created. Lines 5000–5120 show how the error can be corrected. First, the file must be opened for output, read into memory, and closed. The program then asks for the item to be changed (line 5025) and searches for a match (lines 5030–5040). If the item is not found, the program asks for another item to be changed (line 5045). As with the file creation section, entering STOP for the search item ends the entry process.

The program is set up to search for check numbers, but this can easily be changed. For example, if you changed the C$(R,1) in line 5035 to C$(R$,2), you could search for a particular payee name instead. After all corrections have been made, the file is opened again for writing (line 5090), the entire file is rewritten (lines 5095–5115), and finally the file is closed (line 5120).

Adding Data To The File

As your data base grows, so does the length of your file. Lines 6000–6080 show how data may be added to a previously created file. The original file must be opened, read into memory, and closed by the file-reading routine. When data is added to a sequential file, it is added at the end of the existing data. To add data, the computer must know where the last record is located. The reading routine provides that information in the variable R1. Line 6015 checks to see if the file already contains the maximum number of records. Line 6030 starts the addition at the next available record, R1 + 1.

The new data is entered in lines 6035–6045. As before, entering STOP for the check number will end the entry process. Entry will also end when the maximum 25 entries are made. After all the new entries have been made, lines 6060–6080 open the file for writing, write the file (including the new entries), and close the file.

Other Features

The program includes routines to display the records sorted by check number (lines 2000-2060) or by payee name (lines 3000-3050). Both of these use the simple sorting routine in lines 9000-9035. Also included is a routine which will find the payee name and amount when given the check number. As with the correction routine, it would be simple to modify this to search for check number when given the payee name.

Another user-friendly feature is the subroutine at line 9900. This halts the program until you rewind the tape, to insure that you will always begin recording at the start of the file.

Customizing The Program

It may be more efficient to have a separate program for each of the functions, particularly if you have only limited memory, as with the unexpanded VIC. Each of the major routines presented here can be separated into an individual program. Note, however, that most of the routines call other routines. For example, the routine in lines 2000-2055 also needs lines 8000-8040, 9000-9035, and 9900.

The screen displays in the program have been set up for the VIC's 22-column screen. If you are using a 64 or PET/CBM, you can adjust the PRINT statements so that the output will look better on your wider screen display. No other modifications are necessary, but 64 users should remember that the 64 screen display will blank while the program is searching for or reading the file. Also, when the file is found, you'll need to press the Commodore logo key for the reading to proceed.

For unexpanded VICs, not enough memory is available to set up the array for 25 checks. To prevent an OUT OF MEMORY ERROR, you'll have to change the DIM in line 110 to C$(5,3) and the 25 in lines 1025, 6015, 6030, and 8010 to 5. You'll also need to omit spaces everywhere in the program except in the PRINT statements. A file of five records isn't long enough to store a useful amount of information, but it will illustrate the principles of data files. On the other hand, if you have a 64 or PET/CBM, you may have enough memory for arrays of more than 25 rows, and changing the lines mentioned above will allow you to create files with more records.

Disk Modifications

The procedure for creating and manipulating disk data files is essentially the same as that for tape data files. In fact, working with disk files is much easier, since it is not necessary to constantly stop and rewind the tape. Also, the reading and writing is much faster.

To use the program presented here with disk, first delete all the lines which refer to rewinding the tape: 1005, 1010, 2005, 3005, 4005, 5005, 5015, 6005, 6020, and 9900.

These are the lines which must be modified to use the program with a disk drive:

1015 	OPEN	1, 8, 8, "0:CHECK INFO FILE, S, W"
5090 	OPEN	1, 8, 8, "@0:CHECK INFO FILE, S, W"
6060 	OPEN	1, 8, 8, "@0:CHECK INFO FILE, S, W"
8005 	OPEN	1, 8, 8, "0:CHECK INFO FILE, S, R"

Information Handyman For Commodore

Refer to the "Automatic Proofreader" article before typing this program in.