User`s guide

READING
FlLE
DATA: USING
GET#
The
Get#
statement retrieves data from the disk drive, one character at a time. L
ike
the similar keyboard Get statement
in
Basic,
it
only accepts a single character into a
specified variable. However, unlike the Get statement, it doesn't just fall through to
the
next statement if there is no data to be gotten. The primary use
of
Get#
is
to
retrieve fr
om
diskette any data that cannot be read into an Input# statement, either because
it
is
too l
ong
to
fit
in
the input buffer or because it includes troublesome characters.
FORMAT FOR THE
GET#
STATEMENT:
GET#file#
, variable list
where
"file#"
is
the same
file
number given
in
the desired file's current Open statement,
and
"variable
list"
is
one or more valid Basic variable names.
If
more than one d
ata
element
is
to be input by a particular
Get#
statement, each variable name must
be
separated from others by a comma.
In
practice, you will almost never see a Get or
Get#
statement containing more
th
an
one variable name.
If
more than one character
is
needed, a loop
is
used
~ather
th
an
additional variables. Also as
in
the
Input#
statement,
it
is
safer to use string variab
les
when the
file
to be read might contain a non-numeric character.
Data
in
a
Get#
statement comes
in
byte by byte, including such normally invisible
characters as the Carriage Return, and the various cursor controls.
All
but one will be r
ead
properly. The exception
is
CHR$(0), the ASCII Null character.
It
is
different from
an
empty string(oneofthe form
A$="
"),even
though empty strings are often referred to
as
null strings. Unfortunately,
in
a
Get#
statement, CHR$(0)
is
converted into
an
em
pty
string. The cure
is
to
test for
an
empty string after a
Get#,
and replace any that are
fo
und
with CHR$(0) instead . The first example below illustrates the method.
EXAMPLES:
To read a
file
that may contain a CHR$(0), such
as
a machine language program
file
,
we could correct any CHR$(0) bytes with
1100
GET#3
,G$:IF G$ = " " THEN G$ = CHR$(0)
If
an
overlong string has managed to be recorded
in
a
file
,
it
may be safely read b
ack
into the computer with
Get#,
using a loop such
as
this
3300
B$=
....
3310
GET#
I ,A$
3320 IF A$
<>
CHR$(13) THEN
B$=B$+A$
:GOTO 3310
The limit for such a
te
chnique is 255 characters. It will ignore CHR$(0) , but that may
be
an advantage
in
building a text string.
52
Get#
may be especially useful
in
recovering damaged
file
s, or
file
s with unknown
contents. The
Ba~ic
reserved variable ST (the
file
STatus variable) can be used to indicate
wben
all
of
a properly-closed file has been read.
500
GET#2,S$
510
SU=ST
:REM REMEMBER FILE STATUS
520
PRINTS$
; ,
530 IF
SU=
0 THEN 500:REM IF THERE'S MORE TO BE REA L
540 IF SU
<>
64 THEN PRINT " STATUS ERROR: ST = " ;
SU
copying ST into SU
is
often an unneccessary precaution, but must
be
done if any other
file-handling statement appears between the one which read from the
file
and the one that
1oops
back to read again. For example,
it
would be required if line 520 was changed
to
520
PRINT#
l ,S$;
Otherwise, the
file
status checked
in
line 530 would
be
that
of
the write file, not the read
file.
POSSIBLE VALUES OF THE FILE STATUS VARIABLE
''ST'
',
AND l'HEIR MEANINGS
IF
ST=
0
All
is
OK
THEN
I Receiving device
wa
s not available (time out
on
talker)
2 Transmitting device was not available (time out on listener)
4 Cassette data
file
block was too short
8 Cassette data
file
block was too long
16
Unrecoverable read error from cassette, verify error
32 Cassette checksum
error--0ne
or more faulty characters were read
64 End
of
file
reached (EOI detected)
128
Device not present, or end
of
tape mark found
on
cassette
53