EasyManua.ls Logo

Commodore 1570 - Page 68

Commodore 1570
132 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
to
be
sure a carriage return IS included within each 88-character portion
of
the record (88
is
for
BASIC
2,
160 is for
BASIC
7).
If
this is not done, you will have to use the
GET#
command
to
read the record, at a significant cost in speed.
Since
each relative record is most easily written by a single
PRINT#
statement, the
recommended
approach
is
to build a copy
of
the current record in memory before writing
it
to
disk. It can be collected into a single string variable with the help
of
BASIC's
many
string-handling 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
"NAME,"
"STREET,"
"CITY
&
STATE,"
and
"ZIP
CODE,"
and have a total record
size
of
87 characters, we can organize it
in
either
of
two ways:
WITH
FIXED
LENGTH
FIELDS WITH
VARIABLE
LENGTH
FIELDS
Field
Name
Length Field Name
Length
NAME
27 characters
NAME
3 I characters
STREET
27 characters
STREET
31
characters
CITY
&
STATE
23 characters CITY &
STATE
26
characters
ZIP
CODE
10
characters
ZIP
CODE
II characters
Total length 87 characters Potential length
99 characters
Edited length 87 characters
With fixed length records, the field lengths add up to exactly the record length. Since
the total length is
just
within the Input buffer size limitation, no carriage return characters
are needed. With variable length records, you can take advantage
of
the variability
of
actual address lengths. While one
name
contains 27 letters. another may have only 15,
and the same variability exists
in
street and city lengths. Although variable length records
lose
one
character per field for carriage returns, they can take advantage
of
the difference
between
maximum
field length and average field length. A program that uses variable
record lengths must calculate the total length
of
each record as it is entered, to be sure the
total
of
all fields
doesn't
exceed
the space available.
WRITING THE RECORD
Here is an
example
of
program lines to enter variable length fields for the above file
design, build them into a single string, and send them to record
number
RE
in file
number
3
(assumed
to be a relative file that uses channel number 3).
BASIC
7.0:
100
INPUT"ENTER
RECORD
NUMBER";RE
110 :
120
DOPEN#3,
"MYRELFILE"L88
130
CR$=CHR$(l3)
140
INPUT"NAME";
NA$
ISO
IF
LEN(A$»30
THEN
140
160 INPUT" STREET" ;SA$
170 IF
LEN(SA$»30
THEN
160
(continued)
60

Related product manuals