212
Apple
lie
Users
Handbook
SEQUENTIAL
& RANDOM
FILE
ACCESS
Diskettes can be used
to
store
information
other
than a
program.
For
example,
a
diskette
file
can be used
to
star names and
addresses
on
a
mailing
list,
the
result
of
a
formula
, a
letter
,
or
any
other
form
of
data. Such a
file
is
known
as
a
text
file
(or data file).
Text files are
denoted
in
the
catalog listing
with
the
letter
T.
Text files are created, read
from
,
or
written
to
using
the
following
DOS commands in an
Applesoft
or
Integer
BASIC
program
.
OPEN APPEND
CLOSE
POSITION
READ
EXEC
WRITE
OPEN, READ, WRITE, APPEND, and POSITION can
only
be
used
in
the
program
mode.
If
an
attempt
is
made
to
use these
commands
in
the
immediate
mode
,
the
following
error
message
will
appear:
NOT
DIRECT
COMMAND
CLOSE
and
EXEC
may
be
used in
the
immediate
mode
.
Two types
of
text
files are used, sequential
text
files and
random
text
files.
Each
record
of
a sequential disk
file
is
assigned exactly
as
much
disk space
as
it
requires. There are
no
blank
spaces
between
records in a sequential
file
.
In
random
data files, a constant space
is
assigned
to
every
record
in
the
file.
If
the
record
does
not
occupy
the
entire
space
assigned
to
it
,
the
remaining
space
is
left blank.
The
concepts
of
sequential and
random
files are
pictured
in
Illustration
5-15.
Notice
that
the
length
of
each
record
in
the
random
file
is
constant at
100
bytes.
The
record
length
of
a sequential
file
is
variable. The
record
length
is
the
sum
of
the
total space used by all
the
fields in each
i
ndividual
record
.