PRINT
Using PRINT with RELATIVE Files
(See
"OPEN"
for a description of
RELATIVE
file-organization.)
RELATIVE
file
records
can
be
processed
randomly
or
in sequence.
The
cUIlIIJuter
sets
uIJ
<:Ill
illlerlldl
coullLe)
tv
lJuiUL
Lv
Wllich record
should be
processed
next.
The
first record in a file is
record
O.
Thus,
the
counter
begins
at
zero
and
is
incremented
by +1 after
each
file access,
either
to
read
or
to
write
a record. III the exalllple
on
the right,
the
PRINT
statement
directs
the
computer
to write
the file sequentially.
It
can
later
be
processed
either
randomly
or
in
sequence.
The
internal
counter
can
be
changed
by
using
the
REC
clause.
The
keyword
REC
must
be
followed by a numeric-expression whose
value specifies in whiCh position the record in the file is
to
be
written. When the
computer
performs a
PRINT
statement
with a
REC
clause, it begins building an
output
record in the
110
buffer.
When this
record
is
written
onto the file, it will
be
placed
at
the
location specified by
the
REC
clause. You
may
use
the
REC
clause
only with
RELATIVE
files.
The
example
on
the right illustrates
writing
records
randomly, using
the
REC
clause.
Be
sure
to
use
the
REC
clause
if
you
read
and
write
records
on
the
same
file within a
program.
Since
the
same
internal
counter
is
incremented
when
records
are
either
read
or
written
for the
same
file, you
could
skip
some
records
and
write
over
others
if
REC
is
not
used.
as
shown
in the
example
on
the right.
II-134
Examples:
>NEW
>100
OPEN
#3:NAME$,RELATIVE,I
NI~~NAL,OUTPUT,FIXED
1~8
•
program
lines
>150
PRINT
H3:AS,BS,CS,X,Y,Z
•
program
Lines
>200
CLQ~E
H3
>210
END
>N
EW
>100
OPEN
#3:NAME$,RELATIVE,I
NTtRNAL,U~OAI~,tlx~O
lZB
>110
INPUT
K
>120 PRINT
#3,REC
K:A$,B$,CS,
X,Y,Z
•
program
lines
>300
CLOSE
#3
>310
END
>N
EW
>100
OPEN
~3:NAME$,RELATIVE,I
NTERNAL,UPDATE,FIXED
>110
FOR
1=1
TO
10
>120
INPUT
#3:A$,B$,C$,X,Y
>130
PRINT
#3:A~,B$,C$,X,Y
>140
NEXT
I
>150
CLOSE
113
>160
END
LINE
120-reads
records
0,2,4,
6,8
.••
LINE
130-writes
records
1,3,
5,7,
9
•••
User's Reference GUide