EasyManua.ls Logo

Commodore 1570 - Page 57

Commodore 1570
132 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
numeric variables into strings before writing them
to
diskette, and use string functions to
remove any unneeded characters in advance. Doing
so
still allows those data elements to
be
read back into a numeric variable by
INPUT#
later, although
file
data errors may be
avoided by reading all data
in
as
strings, and converting to numbers using the VAL 0
function after the information
is
inside the computer.
For example,
"N$
= RIGHT$(STR$(N),LEN(STR$(N»
-I)"
will convert a posi-
tive number N into a string
N$
without the usual leading space for
its
numeric sign. Then
instead
of
writing
PRINT#5,N,
you would use PRINT#5,N$.
READING
FILE
DATA: USING
GET#
The
GET#
statement retrieves data from the disk drive, one character at a time. Like
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
from diskette any data that cannot
be
read into
an
lNPUT#
statement, either because
it
is
too long 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 data 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
than one variable name. If more than one character
is
needed, a loop
is
used rather than
additional variables. Also as
in
the INPUT# statement,
it
is
safer to use string variables
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 read
properly. The exception
is
CHR$(0), the ASCII Null character. It
is
different from
an
empty string (one
of
the form
A$
=
""),
even though empty strings are often referred to
as
null strings. Unfortunately,
in
a
GET#
statement, CHR$(0)
is
converted into an empty
string. The cure
is
to test for
an
empty string after a
GET#,
and replace any that are found
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, you 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 read back safely
into the computer with
GET#,
using a loop such
as
this
49
------
-----------------------------------------------------------------

Related product manuals