Progamming
Displaying a prompt and waiting
for
a
key
to
be pressed
is
one of the most commonly
PROMPTS
needed actions,
so
it
IS
worth writing a general-purpose procedure. The procedure must
be able
to
display a wide range of messages. A simple
way
of allowing the procedure
to
print any message
is
to
pass
the
message
to
the
procedure
in
the
form
of
a parameter
proc
prompt;
m$
print
m$
+
":
II;
Let
x$
=Lawer(getkey())
print
x$
endproc
The message
to
be displayed
IS
passed
to
the procedure
as
a parameter
In
the local
variable
m$.
The function getkey( ) waits
for
a
key
to
be pressed and returns the
ASCII
code
for
the
key.
In
this procedure the
ASCII
code
is
converted
to
lower case
by
the
function lower(),
so
that the result
IS
independent of upper or lower
case.
Finally the
resulting value
is
assigned
to
the variable
x$.
This
is
a global variable,
so
that the
key
that was actually pressed
IS
available
to
any other procedure
In
the program.
A useful procedure
IS
pause.
It
uses prompt
to
print a message and then Simply waits
PAUSE
until a
key
is
pressed. Since
you
are not usually interested
In
knowing which
key
was
actually pressed,
it
uses a local variable,
y$,
to
preserve the original contents of
x$.
proc
pause
rem
*****
wait
for
any
key
*****
Laca
L
y$
let
y$
=x$
print
prompt;
"press
any
key
to
cant
i
nue"
Let
x$
=y$
endproc
DATA
ENTRY
Accepting
text
as
typed Input
is
qUite
simple. Any collection of characters
is
a valid text
Text
string (even
If It
does not make sense) and
will
not cause an
system
error.
You
will
not
normally need
to
take any special precautions when accepting
text
input.
It
will
usually
be sufficient
to
use a line such
as
the
follOWing,
which
asks
you
to
type
In
your name:
input
"PLease
type
your
name:
";name$
Note that a space
is
included
as
the
last
character of the prompt
text;
this small
pOint
makes a lot of difference
to
the appearance of your program when
you
use
it.
You
can input several items with one Input statement.
All
you have
to
do
is
to
Include
all
the prompts and variable names, separated by semicolons.
input
"Your
first
name?
";fname$;"Your
surname?
";sname$;
This last input statement also ends with a semicolon - this stops the cursor moving
to
the following line after you have typed your Input.
When
you
use the input command
to
enter
text
to
a string variable the computer
will
Numbers
accept anything that you type, without complaint.
If,
however
you
try the same thing
with
input
to
a numeric variable
you
Will
get
an
error message
if
you
type anything except
a valid number Assuming that
you
do
not want
to
leave your program every time your
finger
9ips while
you
are typing
in
a number,
you
must make sure that your program
can cope with such errors.
The most useful way
is
to
make use of the error command, which
was
described earlier
The following procedure,
for
example,
will
accept any valid number within a speCified
range.
It
even provides the display of any prompt message
you
want
to
appear.
12/84 29