136
The VIC 20
User
Guide
Three questions are asked
of
data as it
is
entered.
•
Is
the character a
RETURN?
·
If
the character
is
not a
RETURN,
is
it a valid digit?
· Is the two-character combination a valid month for the first entry, a
valid day for the second entry,
or
a valid year for the third entry?
The
RETURN
has been selected as
an
abort (restart) character.
By
replacing CHR$(13) in lines 60, 160,230, and
1035,
you can select any other
abort character. When the operator presses the selected abort key, the entire
date entry sequence restarts. You must check for the abort character in the
two-character input subroutine (at line 1035), since you want to abort after
the first or second digit has been entered.
The main program also checks for an abort character in order to branch
back
to
the statement in line
10
and restart the entire date entry sequence.
You could branch
out
of the two-character input subroutine and to the
statement in line
10
in the calling program, thereby eliminating the abort
character test in the calling program, but this
is
a bad practice. Every
subroutine should be treated as a module, with specified entry point(s) and
standard subroutine return points.
Using GOTO to branch between the subroutine and the calling pro-
gram
is
likely to be a source of programming errors.
If
you branch out
of
the
subroutine and back to the calling program without going through the
RETURN,
you are making yourself vulnerable to all kinds of subtle errors
that you will not understand until you are
an
experienced programmer.
Program logic that tests for nondigit characters can reside entirely in
the two-character input subroutine. This program ignores nondigit charac-
ters. Statements in lines
1016
and
1036
test for nondigit characters by
comparing the ASCII value
ofthe
input character and the ASCII values for
the allowed numeric digits.
Logic to check for valid month, day, and year must exist within the
calling program since each of these 2-character values has different allowed
limits.
The statement in line
100
tests for a valid month. Statements in lines
120,
130, and
140
compute the maximum allowed day for the month
entered. The statement in line
200
checks for a valid day. The check for a
valid year in line
260
is
very simple.
A numeric equivalent
of
the month
is
generated in line 90, but not for