EasyManua.ls Logo

Commodore VIC-20 - Page 145

Commodore VIC-20
404 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...
Chapter
4
Advanced
BASIC
Progromming 131
This has two implications.
1.
The subroutine must receive parameters from the calling program.
For
example, if a message asks the operator to enter a number, the
calling program should pass the minimum and maximum allowed
numbers to the subroutine as parameters.
2.
The subroutine must return the operator's response to the calling
program. This variable may be a character (for example, Y
or
N), a
word (such as
yes
or no), or a number.
A subroutine that prompts for a reply
ofY
for "yes"
or
N for "no"uses a
PRINT
statement
to
ask the question, followed by a GET to receive a
one-character response. Since you may have many questions in a program
which require a response of "yes" or "no," the subroutine should also allow
for a prompt to be passed to the subroutine from the main program in a
string variable. Here are the necessary statements.
3000
REM
RSK
R
QUESTION
AND
RETURN
A
RESPONSE
OF
Y
OR
N
IN
YN.
3010
PRINT
":']"
302£1
PRINT
"DO
YOU
WRNT
TO
MRKE
ANY
CHANGES?
"i
3030
GET
YNS:
IF
YN'()"N"
AND
YN$()"Y"
THEN
3030
3040
PRINT
YNS
3050
RETURN
The string variable QU$ must be set in the program that calls the
subroutine. The subroutine
is
generalized; that
is,
it displays any prompt.
sent to it by the main program. The response
is
returned to the main
program in the string variable
YN$.
Now consider dialog that allows an operator to enter a number.
Assume that the main program passes to the subroutine the lowest allowable
numeric entry in LO% and the highest in HI%. Once the operator enters a
number within range, the subroutine will return the entered number in
NM%. Here
is
the subroutine that gets the keyboard entry, checks it against
LO% and HI% values, and then passes it back to the main program in
NM%.
3~0e
REM
ASK
FOR
A
NUMERIC
8E~!CTION
3510
REM
RETURN
THE
NUMBER
IN
NM~
3520
REM
REM
NM~
MUST
IE
<-
HI~
AND
>-
~O~
3530
PRINT
QUI;

Other manuals for Commodore VIC-20

Related product manuals