Printer Friendly

Computer filing: how to save data on disk.

Most microcomputer applications published in laboratory journals focus on printing reports, performing calculations, or teaching. While these are useful, they turn the computer into an expensive typewriter or calculator and do not really tap its full power.

One of the strengths of the computer is its ability to store large quantities of information. Word processors, spreadsheets, or laboratory record-keeping systems store data in computer files and make using these files easy by eliminating the need to understand the details of the way the computer handles them.

For some applications, especially word processing, there are so many good commercial programs available that no laboratory needs to write its own. On the other hand, there are applications better done in-house. For example, I needed programs for cost accounting, for workload recording, and to produce tables of contents for procedure manuals. Since I had no software budget and knew of no programs that exactly fit my needs, I wrote my own programs on an IBM PC compatible.

File structures are explained in most Basic manuals, but these manuals are not the easiest way to learn to write code. There are two types of files used in Microsoft Basic: sequential and random access. Sequential files originated with decks of data punch cards that were sequentially processed by the computer. They are easy to code and use in programs but clumsy to update. Random access files are more difficult to code but can be updated as needed.

Sequential files are stored on disk as ASCII text files, while random access files are stored on disk similarly to Basic programs in a specially coded format that is readable only by the computer. (They cannot be listed to the screen or printed out, but data in them can be accessed by whatever program, such as workload recording, is being used in conjunction with the files.)

Files are made up of units called records. A record consists of one set of related data. Originally a record was the material typed on one punch card. In Basic, a record is the material saved by a PRINT or PUT command.

As with a filing cabinet, the first step in using a computer file is to open it. Since sequential files are simpler, they will be discussed first. The syntax for opening a sequential file is:

380 OPEN "TESTFILE" FOR APPEND AS #2

The statement must include the command OPEN, the name of the file being opened in double quotes, a file mode, and a file number. There are three file modes. The input mode reads the file and allows data from it to be used by the program. The append and output modes put data into the file. The difference between the two is that the append mode tacks new data onto the end of the file, while the output mode essentially is for starting a new file or rewriting a file.

A file that is opened in the input mode will not be changed on the disk. These lines of code read an entire file into an array for use by a program:

580 OPEN "TESTFILE" FOR INPUT AS #1

590 COUNT= 1

600 WHILE NOT EOF(l)

610 INPUT # 1,CPT$(COUNT), TEST$(COUNT),

VALUE (COUNT)

620 COUNT = COUNT + 1

630 WEND

640 CLOSE # I In line 610, the data elements in the file are apparent: CPT code, name of test, and workload unit value. First the file is opened. Then a while-wend loop is started. This loop looks for the end-offile marker, a machine-readable code that signals the end of the file. Each record in the file is read into an array by the -input statement until the end-of file marker is reached. The file is then closed by the program. The number I in the EOF, INPUT, and CLOSE statements refers back to the file number in the OPEN statement. This is the computer's way of keeping files separate if more than one is used at a time.

A file that is opened in the output mode will have data written to it starting at the first position in the file. Previously entered data already at this position will be overwritten. This mode can be used to rewrite a file that has been sorted or arranged in a desired order. A file that is opened in the append mode will have new data added at the end of the file.

Data can be printed to files just as it can be printed to a screen or printer. Note the syntax required:

2840 PRINT #I,CK4$(C4);",";TEST4$(C4);","; VALUE(C4)

Again, the # I designates which file is to be printed to. The sequence ;","; that separates each variable name tells the computer to write a variable followed immediately by a comma and then write the next variable to the file. Figure I shows a portion of the file produced by the line above.

Random access files have two major advantages over sequential files. Any record in a random access file can be used, changed, or deleted without affecting the remainder of the file. Since they are stored in a packed binary form, they take up less room on a disk.

The syntax required to set up a random access file is much more complex than that of sequential files. First, each record must be defined exactly. This is done when opening the file and in the FIELD command. Look at the example in Figure 11. The OPEN command contains the letter "R" to indicate random access, a file number, the file name, and the total number of bytes or characters in a record. The FIELD command includes the file number and a list of variables with the number of bytes allocated to each. This tells the computer how much memory to allocate for each record in the file; the total must equal the number of bytes used in the OPEN statement.

To print data to a random access file-to put it onto a diskthe SET and PUT statements are used. Variable names listed in the FIELD statement cannot be used in any other portion of the program. To be used elsewhere in the program, the names have to be converted, as with the LSET commands in lines 520 to 570 of Figure 11. LSET or RSET places the variable to the left or right margin of the space specified for it.

All variables written to random files must be strings, which means they can be alphanumeric. Numeric variables can be convened to string variables by using the MKS$, MKI$, or MKD$ functions for single-precision numbers, integers, and double-precision numbers, respectively. Use of the wrong conversion function will cause errors in reading the data. The PUT statement writes the variables to the disk. It must include a file number and a record number.

To use data that are in a random access file, the same OPEN and FIELD statements that were used to store the data must be included in the program. A GET statement that includes a file number and a record number retrieves one record at a time from the disk.

All variables will be retrieved as alphanumeric strings. Those that are numeric must be converted to the proper form before they can be used in calculations. The CVS, CVI, and CVD functions do this. Once converted, the variables can be used in calculations or can be modified as needed, then PUT back in the file.

Computer files are more challenging to program than much of what is routinely programmed in labs. The usefulness of the files makes them worth the extra effort.

I would be happy to copy the program described here for any reader who sends a formatted 5 1/2inch diskette and a stamped, selfaddressed mailer to me at 622 S. 26th St., Manitowoc, Wis. 54220.
COPYRIGHT 1988 Nelson Publishing
No portion of this article can be reproduced without the express written permission from the copyright holder.
Copyright 1988 Gale, Cengage Learning. All rights reserved.

Article Details
Printer friendly Cite/link Email Feedback
Author:Sehloff, James A.
Publication:Medical Laboratory Observer
Date:Nov 1, 1988
Words:1303
Previous Article:How to stop losing your best workers.
Next Article:AIDS watch: data on exposed health workers.
Topics:


Related Articles
A program to survey susceptibility patterns.
Auditing with your microcomputer; computer software can lead to more efficient audits.
Utility software programs to unclutter your PC.
Software that makes computers easier to use; CPAs should find this list of utilities helpful for all tasks performed on hardware.
An automated system for record keeping, test reporting, and QC in gyn cytology.
A seamless merge of dBase IV data and WordPerfect.
Computer backups checklist.
Five Ways to Manage Your Data Storage.
Watching you secrets windows tells.
FRAGMENTATION INPACTING NEW GENERATION OF COMPUTERS.

Terms of use | Copyright © 2017 Farlex, Inc. | Feedback | For webmasters