In
BASIC 2.0,
to
position the record pointer for channcl
#2
to
record number 3,
type:
PRINT
#15,
"P"
+CHR$(98) +CHR$(3) + CHR$(0)
The CHR$(98) comes from adding the constant (96)
to
the desired channel number (2).
(96 + 2
= 98) Although the command appears
to
work even when 96
is
not
added
to
the
channel number, the constant
is
normally added
to
maintain compatibility with
the
way
RECORD# works in BASIC 7.0.
Since 3 is less than 256, the high byte
of
its binary representation
is
0, and the entire
value
fits
into the low byte. Since you want
to
read or write from the beginning of the
record,
no
offset value
is
needed.
Since these calculations quickly become tedious, most programs are written to
do
them for you. Here
is
an example
of
a program which inputs a record number and converts
it
into the required low-byte/high-byte form:
450 INPUT"RECORD NUMBER DESIRED";RE
460 IF RE<1 OR RE>65535 THEN 450
470
RH
= INT(RE/256)
480 RL=RE-256*RH
490 PRINT#15,
"P"
+CHR$(98) + CHR$(RL) + CHR$(RH)
Assuming
RH
and RL are calculated
as
in
the previous example. programs may also
use
variables for the channel, record, and offset required:
570 INPUT "CHANNEL, RECORD,
& OFFSET DESIRED";CH,RE,OF
630 PRINT#15,
"P"
+CHR$
(CH + 96) + CHR$(RL) +CHR$(RH) +CHR$(OF)
COMPLETING
RELATIVE
FILE CREATION
Now that you have learned how
to
use both
the
Open and Record# commands, you
are almost ready
to
properly create a relative file. The only additional fact
you
need
to
know
is
that CHR$(255)
is
a special character
in
a relative file.
It
is
the
character used
by
the
DOS
to
fill
relative records
as
they are created, before a program fills them with other
information. Thus, if you want
to
write the last record,
you
expect
to
need
in
your
file
with dummy data that will not interfere with your later work, CHR$(255)
is
the
obvious
choice. Here
is
how
it
works
in
an
actual program which you
may
copy for use
in
your
own relative
file
programs.
BASIC 2.0:
1020 OPEN 15,8,15
1380 INPUT"ENTER RELATIVE FILE NAME";FI$
1390 INPUT"ENTER MAX. # OF RECORDS";NR
1400 INPUT"ENTER RECORD LENGTH";RL
(continued)
57
Open command channel
Select
file
parameters