Classic Computer Magazine Archive ANTIC VOL. 3, NO. 1 / APRIL 1984

the toolbox


UPDATE DISKS WITH NOTE AND POINT


by JERRY WHITE

SYNOPSIS
This article shows how to use NOTE and POINT to update files on disk. The program requires BASIC and a disk drive, and works on all Atari computers. You also must use a data file generated by the TELEPHON program (ANTIC, Phone Book, February 1984).

Atari DOS organizes data into sectors, each of which contains 128 bytes. Sometimes, when using data files, we want to access a record directly, without having to go through the time consuming process of checking each record in the file in sequence. Using NOTE and POINT, you can perform what is known as random-access updating.

To use NOTE and POINT, you must first open a file (usually a data file). If you want to determine the file's physical location on the disk, use NOTE X,Y. This returns the current sector number in X, and the current byte within that sector in Y. Use POINT to point to a particular location in a sector also with values for sector and byte. The location that is POINTed to must be within the OPENed file's bounds.

USING "TELEPHON" DATA FILES

This is somewhat different from the method used in the TELEPHON program (ANTIC, Phone Book, February 1984), where we altered records by updating a string in memory. The TELEPHON program stores all of your data temporarily in RAM. Random-access updating allows you to alter data directly on the diskette, as long as you don't change the size of your data file.

In response to reader request, this article and program demonstrate how to use the NOTE and POINT instructions. To use the UPDATE program, you need a data file generated by the TELEPHON program from the February 1984 issue of ANTIC. A few words of caution are in order. It is possible to damage your data file if you enter the UPDATE program incorrectly. Before using this program, format a disk and use DOS option "O" to duplicate your "TELEPHON.DAT" file onto the newly formatted diskette. If anything goes wrong, you can always make another duplicate from your original.

THE UPDATING PROCESS

We begin by opening our data file as shown in line 720. Notice the auxiliary byte 12 in the OPEN command. If it were an eight, we could only write and create a new file. The number 12 allows us to read and write.

The routine that begins at iine 210 reads your data file and creates an index by storing the starting location of each record in two arrays. The variable RECS is used as a record counter. Before we input each record, we note its current location and store the sector and byte numbers in the variables SEC and BYT. We then INPUT each record, and display the record number, disk location and record data on the screen. We also store the sector and byte locations in the index arrays. Once the data has been indexed in this way we can alter as many records as needed without rereading the entire data file, and without reading the entire data file into RAM.

Since we now know where each record begins, we can simply point to the desired record on disk, and then read it into a string (REC$), as shown in line 330. We next make the necessary changes using string manipulation, and create an updated record in the string called WORK$. When we're ready to write our updated information back onto the disk, we simply point back to the original record position as shown in line 550, write the data onto the disk as shown in line 560, close the file, and then reopen it for our next update.

FURTHER NOTES

There are more sophisticated methods of random-access updating, but this one is the easiest to understand. To use it, you must know the record numbers of each record you wish to update. Therefore, it is very important that you make a note of each record number to be changed. You can do this as the program creates its index and displays the necessary information on the screen. To stop the scrolling and give yourself time to write down the desired record numbers, press [CTRL] and [1] simultaneously. To continue, just press [CTRL] and [1] again.

If you still don't understand how the program works, study the program listing. When you read a BASIC program listing, it helps to know the meaning of each variable name. Meaningful variable names are helpful, but a few words of definition also can make a big difference. Chart 1 lists all variables used in the UPDATE program and briefly describes each of them. To make these descriptions easy to find, the variables are listed alphabetically. String names are followed by a dollar sign; array names are followed by an open parenthesis character. All other names are numeric variables.

Chart 1

UPDATE Variable Descriptions

AREA$---area code
BYT----- byte number within sector
BYT(-----byte-number array
EXCH$----telephone exchange
FIRST$---first name
INLEN----length of string
LAST$---last name
PNUM$---last four digits of phone number
REC$-----record data read from disk
RECS-----record-number counter
RNUM-----record number to update
SEC------sectoe number
SEC(-----sector-number array
USER$----user's input from keyboard
WORK$---work string for record update

Jerry White is an institution in the world of Atari computering, and a long-time ANTIC Contributing Editor. This month's column inaugurates "The Tool Box," a new department that will focus on utility programs written in BASIC or for use with BASIC. Jerry will cover other topics on an intermtttent basis.

Listing: UPDATE.BAS Download