Parallax BASIC Stamp 2e Programming Manual page 59

Table of Contents

Advertisement

4: BASIC Stamp Architecture – Constants and Expressions
1
2
2
2
2
e
sx
p
1
2
2
2
2
e
p
sx
You can assign names to constants in a similar fashion to how variables
are declared. On a BS1, it is identical to variable declarations and on the
other BASIC Stamps you use the CON directive. Here is the syntax:
SYMBOL
Name =
ConstantValue
-- OR --
Name
CON
ConstantValue
Once created, named constants may be used in place of the numbers they
represent. For example:
SYMBOL
Cheers
=
FOR Counter = 1 TO Cheers
GOSUB MakeCheers
NEXT
...
-- or --
Cheers
CON
3
' Number of cheers.
FOR Counter = 1 TO Cheers
GOSUB MakeCheers
NEXT
...
That code would work exactly the same as the previous FOR...NEXT
loops. The editor software would substitute the number 3 for the constant
named Cheers throughout your program. 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 downloaded
to the BASIC Stamp, and it often improves the clarity of the program.
Weeks after a program is written, you may not remember what a
particular number was supposed to represent—using a name may jog
your memory (or simplify the detective work needed to figure it out).
Named constants also 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
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 57
3
' Number of cheers.

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?

Table of Contents