proc
choose
rem
*****
choose
an
opt
i on
*****
cLs
print
print"
Add
Despatch
Pay
Change
Wipe
Quit";
print
"?
";
Let
choice$
=Lo_er(getkey())
print
choice$
if
choice$
:;;;lI
a
":
insert:
endif
if
choice$
="d
"
:
despatch:
endif
if
choice$
:;;;"p":
pay:
endif
if
choice$
:;;;"c
rr
:
change:
endif
if
choice$
:;;;II
W
":
wipe:
endif
if
choice$
:;;;llq":
bye:
endif
endproc
All
that remains
to
be done
to
complete our program
IS
to
wnte a
start~up
procedure
which opens the
file
and calls choose.
We
must include choose
In
a loop
so
that
you
are offered the options again, each time
you
complete your previous selection.
You
will
see that the while endwhile loop
In
the following procedure
will
never end. Such
a loop
will
only come
to
an end when the expression following white has a zero
value.
in
the above procedure the expression
always
has the value
1,
so the loop
will
continue
indefinitely. The only way ot leaving this loop
is
to
choose the
QUit
option. The stop
command
in
bye immediately returns control
to
the keyboard.
proc
start
*****
rem
start
procedure
*****
c L5
open
"newma
it.
dbf"
_hi
te
1
error
choose
tet
n
=errnum()
if
n
print
"Mistake
-
Press
any
key
to
continue"
Let
m$
=getkey()
endif
end_hi
Le
endproc
Within this loop
is
a sequence of statements which handles any errors,
uSing
a similar
method
to
that described
in
the prevIous section.
If
you
make a mistake the program
will
not continue until you press a
key.
This
allows
you
to
look
at
what
you
have
Just
done so that you can find out how
you
made the error
The main procedure
in
the mailing
list
program
is
called
"start':
This
IS
so
that
you
can
use the run command when
uSing
the program
We
have already used this command
when
we
used the "loader" program
to
load the
'gazer
data
file
Save this final procedure
in
"maillisr. When
you
want
to
run the program
you
will
need
to
load
the
procedures
into
the computer's memory and then execute
the
main procedure,
which
Will
call
all
the others. One
way
is
to
use the load command and then type
In
the name of the main procedure, for example:
toad
"mai
II
i
st"
start
The run command will load a named program and then automatically execute the
procedure called
"start"
(if
it
exists).
You
can run the program exactly
as
in
the prevIous
example just by typing:
run
"mai
II
i
st"
The remaining two sections of this chapter include some general purpose procedures
which
you
may find useful.
Most variables that appear
in
procedures
are
global.
This
means that
they
are recognised
throughout the program. They may be used or changed
in
any procedure, and not
Just
the procedure
In
which they are
first
assigned a
value.
12':84
Programming
THE
RUN
COMMAND
LOCAL
VARIABLES
27