Programming
22
Insertion
We
do not need
to
write a procedure to
add
a record.
We
can use insert. Remember
that you must use sprint
to
force the display of the contents of the record trom within
a procedure.
You
can use insert immediately
to
add a few records
to
the file
so
that
you can test the other procedures on a real
file.
Deletions
At some time you
will
want
to
remove the records
of
people who have not renewed
their subscriptions.
We
shall write a procedure, wipe, which allows you to scan through
the
file,
examining the records
of
all
people who have not renewed, and
to
deCide which
should be deleted.
We
shall use the field variable issues
to
hold the number
of
Issues that a person
IS
entitled
to receive.
All
records for which the value of issues
is
zero are therefore candidates for
deletion.
proc
wi
pe
rem
*****
delete
non-paying
subscribers
*****
cLs
dispLay
se
lect
issues
=0
aLL
sprint
print
at
18,0;
"DELETE
(yin)?
";
Let ok$
=Lower(getkey())
print
ok$
if
ok$
=llyll
detete
print
"DELETED";
tab
15
else
print
tab
15
endit
endaLL
reset
endproc
Since a deleted record cannot be recovered, the
full
contents of the record are displayed
and
you
are asked
to
confirm that
you
really want
to
delete
it
We
use the getkeyO function
which walts for a
key
to
be pressed and then returns the ASCII
code
of that
key.
Note
that lowerO converts the code to the lower case character
so
that you can type the letter
In
either
upper
or lower case.
Once you are satisfied you have correctly entered this procedure, you may try
it
out
on your
file,
(provided, of course, that you have entered some test records).
First,
leave
edit by pressing ESC (twice
if
necessary) and
save
your procedure
in
a
file
called
"Maillist':
~~.
C
save
"Mai
II
i
st"
The procedure called wipe
IS
now stored and can be called whenever "Mailllst':
IS
loaded.
After entering each of the
follOWing
procedures, repeat these steps, each time storing
the new procedure
In
"Maillist':
Payments
You
will normally want
to
record a batch of subscription payments from a list
of
names
and addresses.
You
will
therefore need
to
get the record of a particular person. The
qUickest way
is
to
write a separate procedure, getrec,
to
locate a particular record and
then Incorporate
it
In
a pay procedure.
The getrec procedure asks for a text string (n$) and then locates the first record
in
the
file which contains that
text.
If
you reply by just pressing ENTER, n$
is
set to the empty
string and no search
is
made.
This
will,
however,
Indicate that you have finished recording
payments.
12/84