Procedures
18
proc
vufi
Le
cLs
input
"which
fi
Le?
";fi
le$
Look
fiLe$
dispLay
let
key$="z"
whi
le
key$<>"
q
"
sprint
Let
key$=lower(getkey())
if
key$="f
l
':first:endif
if
key$="l":Last:endif
if
key$="nll:next:endif
if
key$="b":back:endif
endwhi
le
close
endproc
Remember that
you
leave edit by pressing ESC
tWice.
You
can
use
the procedure by typing:
vufiLe
It
will
first
clear the display area and then prompt
you
to
type
in
a
file
name such
as
'gaze!':
If
'gazet"
IS
already loaded,
however,
you
will
receive
an
error message.
To
recover,
type new and load and run the procedure again. When you have entered the name
of one of your data
files
the procedure
will
open that
file
,n
read-only mode and display
ItS
first
record.
It
will
then wait
for
you
to
press a
key
and will respond
to
the
keys
f,
I,
n,
b or
q.
The
first
four of these
Will
cause the appropriate display action
(first.
last.
next or back) and pressing the q (quit)
key
will
close the
file
and end the procedure.
Since this
is
the first program of any great length that
we
have written, a
few
comments
might prove helpful.
First
note how the example
is
indented
to
clarify the structure of
the procedure. There
IS
no need for
you
to
type
it
like
this,
the Indents are added
automatically
as
you
write,
list
or
print the procedure.
The main part
of
the procedure (waiting for a
key
to
be pressed and performing the
appropriate action)
IS
enclosed between while and endwhile commands. This repetitive
loop
Will
only be
left
when the condition
follOWing
while
is
false,
in
this
case,
when you
press the q
key.
The if command, used
several
times within
thiS
loop, also requires that each if has a
matching endif
to
mark the end of the sequence of instructions
to
be executed
if
the C
condition
is
true.
If and endif are separate commands and can be used on different
'.
/
hnes.
We
could,
for
example,
have
written
the
nrst
of the if statements
in
this procedure
as:
if
key$="f"
firs
t
endif
You
may include
several
lines
of
statements between if and end
if;
they
will
all
be executed,
provided the condition
follOWing
if
is
true.
In
the vufile procedure these statements are
sufficiently short that each can be written
on
a single
line,
using the colon
to
separate
,the individual statements.
As
you can
see,
a sprint command
is
used
Within
the main loop of this procedure
to
make sure that each new record
is
shown
on
the screen. Remember that. although
the display commands (first, last
etc.)
always move
to
the correct record, the data
in
the display area
is
not automatically changed until the end of the procedure.
If
we
had
not included the sprint command, no information wculd have been shown
in
the display
area
until
you pressed the q
key
to
leave the procedure.
In
that case
all
you
wculd see
wculd be the result of the
last
of any sequence of keypresses that
you
have made.
12/84