Expanding A Relative File - Commodore 1541 User Manual

Hide thumbs Also See for 1541:
Table of Contents

Advertisement

1410 OPEN 1,8 ,2,
"
O:"+
FI$+" ,L,"
+CHR$(RL)
1420 GOSUB 59990
1430 RH= lNT(NR/256)
1440 RL=NR-256*RH
1450 PRINT#l5, "P" + CHR$(96 + 2) +
CHR$(RL) + CHR$(RH)
1460 GOSUB 59990
1470 PRINT#l,CHR$(255);
1480 GOSUB 59990
1490 PRINT#l5
,
"P"+CHR$(96+2)+
CHR$(RL) + CHR$(RH)
1500 GOSUB 59990
1510 CLOSE I
1520 GOSUB 59990
9980 CLOSE 15
9990 END
59980 REM CHECK DISK SUBROUTINE
59990 INPUT#l5,EN ,EM$,ET,ES
Begin to create desireQ
Check for disk
errors
Calculate length
VaJu
Cs
Position to last
record
number
Send default
character
to
Re-position
for
safety
Now the file can
be
sai
closed
And the
command
eh
closed
Before we end
the
pro.
gram
G RELATIVE
FILE DATA
1be
commands
used to read and write relative file data are the same Print#
,
Input#
,
(jtl.# commands used in the preceding chapter on Sequential files. Each command
is
,J
15
described
there
. However,
some aspects of relative file access do differ from
~al
file
programming
,
and we will cover those differences here
.
AS
seated
earlier in this chapter, each relative record has a fixed length
,
including all
·ial
characters
.
Within
that
fixed length, there are two popular ways to organize
~oUS
individual
fields of information
.
One is free-format, with individual fields
varying
i0gth
from
record to record
,
and each field separated from the next by a carriage return
(each of which does take up 1 character space in the record)
.
The other approach
~
use
fixed-length
fields, that may or may not be separated by carriage returns
.
If fixed
fields
are not all separated by carriage returns, you will either need to be sure a
return
is included within each 88 character portion of the record
.
If this is not
' O
C.
you
will
have to use the Get# command to read the record
,
at a significant cost in
Relative records of 88 or fewer characters, or final portions of records that are 88 or
0
ercharacters in length, need not end in a carriage return
.
:fhe 1541 is smart enough to
·ognize
the
end of a relative record even without a final• carriage return
.
Though the
1
1ng
of
a
single character isn't much, when multiplied by the number of
records
on a
60000 IF EN
>
1 AND EN<>50 THEN PRINT
EN ,EM$,ET ,ES :STOP
Ignore
"RECORD
NOT
ette,
the
savings could be significant.
PRESENT"
Since each relative record must be written by a single Print# statement
,
the
recom-
60010 RETURN
Two lines require additional explanation
.
When line 1470 executes, the disk
drive
(
operate for up to ten or more minutes
,
creating all the records in the file
, up to
maximum record number you selected in line
1390.
This is normal
,
and only
needs
to
done once
.
During the process you may hear the drive motor turning and an
occasi
slight click as the head steps from track to track
,
everything is probably just
fine
.
Sec
ndcd
approach
is to build a copy of the current record in memory before writing it to
it
It can be collected into a single string variable with the help of Basic
'
s many
string-
.
g
functions,
and then all written out at once from that variable
.
Here
is
an example
.
If we are writing a 4-line mail label
,
consisting of 4 fields named
AME",
"STREET"
,
"CITY &
STATE",
and
"
ZIP CODE
",
and have a total record
of87 characters, we can organize it in either of two
ways:
line 60000 above is different from the equivalent line in the error check
subroutine gi
1
earlier. Here disk error number 50 is specifically ignored
,
because
it
will be
gene.
Id N
when the error channel is chec;ked in line
1460.
We ignore it because not
havtn!
ame
Length
WITH VARIABLE LENGTH FIELDS
Field
Name
Length
requested record would only be ail error if that record had previously been
created.
\ME
27
characters
NAME
3
1
characters
EXPANDING A RELATIVE FILE
What if you underestimate your needs and need to expand a relative fil
e
later?
problem
.
Simply request the record number you need, even if it doesn't
currently
e~
1
the file
.
If there is no such record yet,
oos·
will create it as soon as you
try to
~
information in it
,
and also automatically create any other missing records
beloW
11
number. The only penalty will be a slight time delay while the
records
are
created.
60
27
characters
STREET
3
1 character
23
characters
CITY & STATE
26
characters
I 0
characters
ZIP CODE
1
I
characters
87
characters
Potent ial length
99 character
Edited length
87
charac
ter
With fixed length
records. the
fi eld
lengths
add up
to
exactly
the
record length
.
Si nce
·
1
otal
length
is just within
the
Input buffer
size limitation, no
carri
age
return
charac
ters
:
ileeded. With
variable
length
records, we
can
take advantage of the vatiability of
<Ja!
address
lengths
.
While one name contains
27
letters.
another
may have
onl
y 15,
.the
same variability
exists
in Street and City length
s.
Al though vari
able
length
record
1
character per
fie
ld for
carriage returns, they ca
n
take advantage of the
difference
61

Advertisement

Table of Contents
loading

Table of Contents