English
Language : 

NSB8 Datasheet, PDF (110/158 Pages) List of Unclassifed Manufacturers – BASIC interpreter for Z80 family
grifo®
ITALIAN TECHNOLOGY
TYPES OF DATA ELEMENTS IN FILES
Three types of data may be stored in BASIC data files: numbers, strings, and separate bytes. Each
type of item takes up a certain amount of space on the file when it is stored. Numbers always take
up a fixed amount of space. This space is sufficient to hold any numeric value. Strings can take up
variable amounts of space, depending upon the current length of the string when it is written to a
file. Separate byte values require only one byte of disk storage space to store. Each element of byte
information contains a binary integer value from 0 to 255.
BASIC writes strings and numbers to data files using a certain well defined formats. Consequently,
it is easy for BASIC to recognize string and numeric data when a file is READ. Bytes, however,
cannot be so identified. The programmer must always know when byte data will be encountered
during file reading and writing. If such knowledge is not available to a file reading program, it may
be impossible for that program to make sense of a file’s contents.
DATA ACCESS
The two statements which permit input from a file and output to a file are READ# and WRITE#. READ#
inputs data from a file and assigns it to variables as specified by the programmer. WRITE# overwrites
any previously existing information at a given point in the file with new information, also as specified
by the programmer (see statements READ# and WRITE# for specific details). READ# and WRITE#
may be used to access string, numeric, or byte valued information in sequential or random
fashion. The rest of this chapter examines these data access methods.
SEQUENTIAL ACCESS
The simplest files consist of sequences of data values (all string, all numeric, all byte, or combinations
of these). This means that the first data value is located at the start of the file, and succeeding values
follow immediately afterward, one after another. BASIC automatically places a special end of file
mark (called an endmark) after the last value in a sequential file. This facilitates later reading of the
file, because the endmark may act as a signal to the program to quit reading, lest a program error occur
when an attempt is made to READ (or READ past) the endmark.
A check for the endmark can be made with the built in TYP function. TYP, when supplied with the
number of an open file as argument, returns the numeric code for the type of the next element to be
READ from that file:
TYPE
0
1
2
NEXT VALUE
endmark
string
number
Therefore, if the value of TYP(1) is 0, then the end of file #1 has been reached, and no more reading
from that file should be attempted. The TYP function also permits a program to know whether to
READ a string or numeric value next, since the types for those data elements are also returned. This
is important, because a program which tries to READ a numeric value into a string variable, or a string
value into a numeric variable will generate a TYPE ERROR. With this in mind, here is a program
which reads an existing sequential data file whose contents include an unknown sequence of
intermixed string and numeric values, then prints the contents to the console terminal:
Page 98
NSB8
Rel. 5.10