File Limits; Creating A Relative File; Using Relative Files: Record - Commodore 1541 User Manual

Hide thumbs Also See for 1541:
Table of Contents

Advertisement

desired person out of
a
thousand in under 15
seconds
,
a feat
no
sequential
file
could match
.
progralli
FILE LIMITS
. One of the nicest aspects of relative files is that all this is done for you without
0
havmg to worry at .all
~bout
exactly where on the diskette's
surface
a given
record
wiii
Ur
stored,
or whether 1t will fit properly within the current disk
sector or
need to be
ext
d
he
onto.
the next available sector. DOS takes
care
of
all
that for
you'.
All you need
to
e~o ~d
specify
how long
eac~
reco.rd is: in bytes, and how many records you
will
need
. DOS
1
,/
do the rest'.
a~d ~rgan~ze
thmgs m
such
a way that it
can
quickly find
any
record
in
the
fii
11
as soon as It is ~1~en Its re~ord number
(ordinal
position
within
the file)
.
e,
The only hm1t that will concern you, is that
each
record must be the
same
siz
the record length you choose must be between
2 and
254
characters
Naturally
theee,
and
file I
h
fi
·
.
·
nt1re
a so as to t on your diskette too, which means that the more records you
need
th
shorter each must be
.
· e
CREATING A RELATIVE FILE
.
When a relative file
is
to be used for the first time, its Open
statement
will
create the
file,
af~e~
that, the
same
Open
statement will
be used to re-open the file for both
read·
and wntmg
.
ing
FORMAT STATEMENT TO OPEN A RELATIVE
FILE:
OPEN file #
,
device#
,
channel
#
,
"drive
#
:
file name, L"
+
CHR$
(record
length)
'
where
'.
' file#" is the file number, normally an integer between I
and
127;
"device#
"
is
the device numbe.r to be used'.
no~ally
8 on the 1541;
"channel
#"
selects a
particular
ch~~~el
.along.~~1ch
co~municatJOns
for this file
can
take place, normally between
2 and
14,
dn:e #
is .the dnve number,
always
0 on the 1541
;
and
"file
name"
is
the file
?ame, with a maximum length
of
16
characters
.
Pattern matching characters
are
allowed
'.~
the name
~~~n acc~ssing
an existing file
,
but not when
creating a
new
one.
The
record
length.
is the
size
of
each
record within the file in bytes used, including
carriage
returns
,
quotation marks and other
special characters
.
56
Notes:
I
.
Do not precede the drive number with the
"at"
sign(@
);
there
is
no reason
to replace
a relative file
.
2.
,L , "+
CHR$(record length) is only required when a relative file
is
first
created,
though it may used later, so long as the
"record
length" is the
same
as
when
the file was first created
.
Since relative files may be read from or written to
alternately
and with equal ease, there is no need to
specify
Read or Write mode
when
opening a relative file.
3. "file#",
"device#"
and
"channel#"
must be valid numeric constants,
variables
or expressions
.
The rest of the
command
must be a valid
string
literal,
variable
or expression
.
4. Only I relative file can be open at a time on the 1541, although a
sequential
file
and the command channel may also be open at the same
time.
EXAMPLES:
To
create or re-open a relative file named
"GRADES"
,
of record length
100,
use
OPEN
2,8,2,"GRADES,L," +CHR$(100)
To
re-open
an unknown relative file of the user's
choice
that has already been
created,
we could use
200 INPUT''WHICH ALE'';A$
210 OPEN
5,8,5,A$
USING
RELATIVE FILES: RECORD#
When
a relative file is opened for the first time, it
is
not quite ready for use
.
Both to
save
time
when using the file later, and to assure that the file will work reliably, it is
necessary
to create several records before closing the file for the first time. At a minimum,
enough records to fill more than 2 disk sectors
(512
bytes)
should
be written
.
In practice,
most
programs
go ahead and create as many records as the program is
eventually
expected
to
use.
That approach has the additional benefit of avoiding
such
problems as running out
of
room
on the diskette before the entire file is completed.
If
you simply begin writing data to a just-opened relative file, it will act much like
a
lequential
file, putting the data elements written by the first Print# statement in Record
II,
those
written by the second Print# statement in record #2 and
so
on
.
(As
this
implies, each relative record must be written by a
single
Print# statement, using embed-
ded
carriage
returns within the data to separate fields that will be read in
via
one or more
Input#
statements later.) However, it is far better to explicitly specify which record
~Urnber
is desired via a Record# command to the disk
.
This allows you to access records
Ill
any desired
order, hopping anywhere in a file with equal
ease.
Properly used, it
also
avoids a subtle error
(bug)
common to all Commodore disk drives
.
57

Advertisement

Table of Contents
loading

Table of Contents