Specifications

BASIC Stamp II
Page 226 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
For example:
99 decimal
%1010 binary
$FE hex
“A” ASCII code for A (65)
You can assign names to constants using the CON directive. Once cre-
ated, named constants may be used in place of the numbers they rep-
resent. For example:
cheers con 3 ‘ Number of cheers.
FOR count = 1 to cheers
GOSUB makeCheers
NEXT
...
That code would work exactly the same as the previous FOR/NEXT
loops. The Stamp host software would substitute the number 3 for the
constant name cheers throughout your program. Note that it would
not mess with the label makeCheers, which is not an exact match for
cheers. (Like variable names, labels, and instructions, constant names
are not case sensitive. CHEERS, and ChEErs would all be processed as
identical to cheers.)
Using named constants does not increase the amount of code down-
loaded to the BS2, and it often improves the clarity of the program.
Weeks after a program is written, you may not remember what a par-
ticular number was supposed to represent—using a name may jog your
memory (or simplify the detective work needed to figure it out).
Named constants have another benefit. Suppose the “Three Cheers”
program had to be upgraded to “Five Cheers.” In the original example
you would have to change all of the 3s to 5s. Search and replace would
help, but you might accidentally change some 3s that weren’t num-
bers of cheers, too. A debugging mess! However, if you made smart
use of a named constant; all you would have to do is change 3 to 5 in
one place, the CON directive:
cheers con 5 ‘ Number of cheers.