DISK BASIC
illl
Methods
of Access
Disk basic
provides
two means
of
file
access:
•
Sequential
—
in
which you
start
reading or
writing data
at
the
beginning
of
a
file;
subsequent
reads or writes
are
done
at
following
positions
in
the
file.
•
Random
—
in
which you
start
reading or
writing
at
any
record
you
specify.
(Random
access
is
also called direct access.)
Sequential access
is
stream-oriented;
that
is,
the
number
of
characters
read or
written
can
vary,
and
is
usually
determined
by
delimiters
in
the data.
Random
access
is
record-oriented;
that
is,
data
is
always
read or
written
in
fixed-length
blocks
called records.
To do any
input/output
to
a disk
file,
you must
first
open
the
file.
When
you
open
the
file,
you
specify
what
kind of
access
you
want:
•
o
for
sequential
output
•
i
for sequential input
•
r
for
random
input/output
•
e (Extend)
for sequential
output
starting
at
the
end
of
file.
You
also
assign a
file
buffer
for
basic
to
use during
file
accesses.
This
number
can be
from
1
to 15,
but
must
not
exceed
the
number
of concurrent
files
you
requested
when
you
started
basic
from
trsdos. For example,
if
you
started
basic with
3
files,
you
can use
buffer
numbers
1,
2,
and
3.
Once
you
assign a
buffer
number
to
a
file,
you
cannot
assign
that
number
to
another
file
until
you
Close
the
first file.
Examples
OPEN
"0"
t
1
*
"TEST"
Creates
a sequential
output
file
named
test on
the
first
available drive;
if
test
already
exists,
its
previous contents
are
lost.
Buffer
1
will
be used
for
this
file.
OPEN
"I"
t
2*
"TEST
1
Opens
test
for sequential input,
using buffer
2.
OPEN
"R"
t
i
*
"TEST"
Opens
test
for direct access,
using buffer
1
.
If
test does
not
exist,
it
will
be
created
on
the
first
available
drive.
Since record
length
is
not
specified,
256-byte
records
will
be
used.
OPEN
"R"
t
1
t
"TEST"
t
40
Same
as
preceding example,
but 40-byte records
will
be
used.
OPEN
"E"
f
1
*
"TEST"
Opens
test
sequentially for write
and
positions
to
EOF.
145