
"channel
#"
is a secondary address, giving further instructions to the selected
device about how further commands are to be obeyed. In disk files, the channel number
selects a particular channel along which communications for this file can take place.
Th
e
possible range
of
disk chan!'el numbers is 0-15, but 0
is
reserved for program Loads, I for
program Saves,
and
15
for the disk command channel. Also be sure that no two disk files
have the same channel number unless they
wiIJ
never be open at the same time. (One
wa
y
to do this is to make the channel number for each
.file
the same as its file
pumber.)
"drive#"
is the drive number, always 0
on
the 1541. Do not omit it,
or
you will
only be able to use two channels at the same time instead
of
the normal maximum
of
three.
If
any pre-existing file
of
the same name
is
to be replaced, precede the drive number with
the
"at"
sign(
@)
to request Open-with-replace.
"file
name"
is the file name, maximum length
16
characters. Pattern matching
characters are allowed in the name when accessing existing files , but not when creating
new ones.
"file
type"
is the file type desired:
S=sequential,
P=program,
U=user,
and
L
=length
of
a relative file .
"direction"
is
the type
of
access desired. There are three possibilities: R
=read
,
W
=write
, and M
=modify
. When creating a file , use
"W"
to write the data to diskette.
When viewing a completed file, use
"
R"
to read the data from diskette. Only use the
"M"
(modify) option as a last ditch way
of
reading back data from an improperly-closed
(Splat) file .
(If
you try this, check every byte as
it
is read to be sure the data is still valid,
as such files always include some erroneous data, and have no proper end.)
"file
type"
and
"dir
.
ection"
don't
have to be abbreviated. They can be spelled out
in full for clarity
in
printed listings.
"file#",
"device#"
and
"channel#"
must be valid numeric constants, variables
or
expressions.
The
rest
of
the command
mus~
be a valid string literal, variable or
expression.
The
maximum number
of
files that may be open simultaneously
is
10, including all
files to all devices.
The
maximum number
of
sequential disk files that can be open at once
is 3 (or 2 if you neglect to include the drive number
in
your Open statement), plus the
command
channel.
EXAMPLES
OF
OPENING
SEQUENTIAL
FILES:
To
create a sequential file
of
phone numbers, you could use:
OPEN
2,8
,2,
"O:PHONES,SEQUENTIAL,
WRITE"
or
save yourself some typing with:
OPEN
2,8,2,"0:PHONES,S,W"
On
the off-chance
we've
already got a
"PHONES"
file on our diskette, we can avoid a
" FILE
EXISTS"
error message by doing an @OPEN
OPEN
2,
8,2,
"@O:PHONES,S,W"
44
Of
course, this erases all
our
old phone number
s,
so make sure that any information that
1118
y
be
deleted is
of
no importance. After writing
our
phone file, we remove our
di
skette
and tum
off
the system. Later, to recall the data
in
the file, we would reopen
it
with
something like
OPEN
8,8
,
8,
" 0:
PHONES,S
,R"
It doesn
't
matter whether the
file
and channel numbers match the ones we used before, but
the file name does have to match. However.
it
is possible to use an abbreviation form
of
the file name, if there are no other files that would have the same abbreviation:
OPEN
10
,8,
6,
"O:PH*
,S,R"
If
we have too many phone numbers, they might not
fit
in
one file .
In
that case, we
might use several similar file names, and let a program choose the correct file .
100
INPUT
"WHICH
PHONE
FILE ( l-
3)"
;PH
110
IF PH
<>
I AND PH
<>2
AND
PH
<>3
THEN 100
120 OPEN 4
,8,2,"
PHONE" +
STR$(PH)+
",
S,R"
You
can omit the drive number on an Open command to read a file. Doing so allows those
with dual drives to search both diskettes for the file .
Note: Basic 2 and Basic 3.5 use the same file handling commands and the same
direct access commands (chapters 7-8).
Unless otherwise noted, you may use the
same commands for both throughout the remainder
of
this book.
ADDING
TO A SEQUENTIAL FILE
On
Commodore's
PET
and
CBM
models, an Append command allows you to reopen
an
existing sequential file and add more information to the end
of
it.
The
same thing can
be
done another way on the 1541. In place
of
the " type" and
"direction"
parameters
in
your
Open
statement, substitute
",A"
for Append. This will reopen your file, and
position the disk head at the end
of
the existing data
in
your file, ready to add to it.
FORMAT
FOR
THE
APPEND
OPTION
OPEN
file # ,device # ,channel
#,"drive
#:file
name,A"
Where.
everything is as on the previous page except for the ending
"A"
replacing the
"type"
and
"direction"
parameters.
45
Kommentare zu diesen Handbüchern