Writing The Record - Commodore 1541 User Manual

Hide thumbs Also See for 1541:
Table of Contents

Advertisement

between maximum field length and average field length. A program that
uses
v
.
record lengths must calculate the total length of each record as it is entered
,
to
be
8
total of all fields doesn't exceed the space available.
Ure
WRITING THE RECORD
Here is an example of program lines to enter variable length fields for the
abov
design
,
build them into a single string, and send them to record number
RE
in
file
nuc
3 (assumed
to
be a relative file that uses channel number 3)
.
150
CR$=CHR$(13)
2000 INPUT"NAME";NA$
2010
IF
LEN(NA$)>30 THEN 2000
2020 lNPUT"STREET" ;SA$
2030 IF LEN(SA$)>30 THEN 2020
2040 INPUT"CITY & STATE";CS$
2050 lF LEN(CS$)>25 THEN 2040
2060 lNPUT"ZIP CODE" ;ZP$
2070 lF LEN(ZP$)> 10 THEN 2060
2080 DA$ = NA$+ CR$+ SA$+ CR$+
CS$+ CR$ + ZP$
2090 lF LEN(DA$)<87 THEN 2120
2100 PRINT"RECORD TOO LONG"
2110 GOTO 2000
2120 RH= INT(RE/256)
2130 RL=RE-256*RH
Carriage
Return
Enter fields
And check length of
each
Build output data
string
Check its length
If too
long
overall
Calculate record
number
' J f1J_
IF
LEN(SA$)>27 THEN 2020
~SA$=
SA$+ LEFT$(BL$ ,27-LN)
fl' I J
(NPUT"CITY
& STATE";CS$
~
LN
=
LEN(CS$)
;,so
IF
LEN(CS$)>23
THEN 2040
j,sS
CS$
=
CS$+ LEFT$(BL$ ,23 -LN)
~
INPUT"ZIP
CODE" ;ZP$
' f lJS
LN
= LEN(ZP$)
f10IFLEN(ZP$)>10 THEN
2060
~S
ZP$
= ZP$
+
LEFT$(BL$
,
10-LN)
~
DA$
=NA$+
SA$+ CS$+ ZP$
:120
RH=
lNT(RE/256)
' . 1J0
RL
= RE-256*RH
;,40
PRINT#15,
"P" +CHR$(96
+
3)
+
.
CHR$(RL)
+ CHR$(RHl + CHR$
(I)
!ISO
GOSUB
59990
!160
PRINT#
3 ,DA$
;
:170
GOSUB
59990
!i80
PRINT#l5
,"P" +CHR$(96+3)
+
CHR$(RL)
+ CHR$(RH)
+
CHR$
(I)
:190
GOSUB
59990
Note lack of
separators
Note added
semicolon
If
field
contents vary in length
,
variable field lengths are often preferable
.
On the
' C her
hand
,
if the field lengths are
stable,
fixed field lengths are preferable
.
Fixed length
ields
are
also required if you want to use the optional offset parameter of the Record#
;oounand to
point at a particular byte within a record
. However,
one warning must be
13dc
about
using the offset this way
.
When any part of a record is written
,
DOS
2140 PRINT#l5,"P" +CHR$(96+3)+
CHR$(RL) + CHR$(RH)
2150 GOSUB 59990
vcrwrites any remaining spaces in the record
.
Thus, if you must use the offset option,
Position to
record
number RE
:ever
update
any field in a record other than the last one unless all
succeeding
fields will
Check for disk errors
ilsobe
updated
from memory later.
2160 PRINT#3,DA$
2170 GOSUB 59990
2180 PRlNT#l5,"P" +CHR$(96+3)+
CHR$(RL) + CHR$(RH)
2190 GOSUB 59990
Send data to it
.
The
above programs are careful to match record lengths exactly to the
space
•11ilable. Programs
that don't do so will discover that DOS pads
short
records out to full
Re-position
for
safety
1
1.e
with fill
characters, and tri.mcates overlong records to fill only their allotted
space.
Yihen
a
record
is truncated, DOS will indicate error 51,
"RECORD
OVERFLOW", but
~records
will be accepted without a DOS error message
.
To use the above program lines for the version with fixed length
fields, we
YI
•~·-
alter a few lines as follows
:
""'WING
A RELATIVE RECORD
150
160 BL$="
2000 INPUT"NAME";NA$
2005 LN
=
LEN(NA$)
2010 IF LEN(NA$)
>
27 THEN 2000
2015 NA$
=
NA$+LEFT$(BL$ ,27-LN)
2020
JNPUT"
STREET";SA$
2025 LN
=
LEN(SA$)
62
Not needed this time
27 shifted space
characters
Checking for
different
tengthl
And padding to
preset sizes
Once
a relative record has been written properly to diskette, reading it back into
-lllputer
memory
is fairly
simple,
but the procedure again varies
,
depending on whether
illes
fixed
or variable length fields
.
Here are the program lines needed to read back the
lllable
fields
created above from record number RE in file and channel
3:
~RH=
INT(RE/256)
llO
RL
= RE-256*RH
120
PiUNT#l5,
"P"
+ CHR$(96 + 3)+
CJ.iRS(RL)
+ CHR$(RH) + CHR$ ( 1)
63
Calculate record number
Position to record number
RE

Advertisement

Table of Contents
loading

Table of Contents