Specifications

BASIC Stamp II
Page 218 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
does have predefined variables that you can use without declaring them
first (see previous section), the preferred way to set up variables is to
use the directive VAR. The syntax for VAR is:
symbol VAR size
where:
Symbol is the name by which you will refer to the variable. Names
must start with a letter, can contain a mixture of letters, numbers,
and underscore (_) characters, and must not be the same as
PBASIC keywords or labels used in your program. Additionally,
symbols can be up to 32 characters long. See Appendix B for a list
of PBASIC keywords. PBASIC does not distinguish between
upper and lower case, so the names MYVARIABLE, myVariable,
and MyVaRiAbLe are all equivalent.
Size establishes the number of bits of storage the variable is to
contain. PBASIC2 gives you a choice of four sizes:
bit (1 bit)
nib (nibble; 4 bits)
byte (8 bits)
word (16 bits)
Optionally, specifying a number within parentheses lets you define a
variable as an array of bits, nibs, bytes, or words. We’ll look at arrays
later on.
Here are some examples of variable declarations using VAR:
‘ Declare variables.
mouse var bit ‘ Value can be 0 or 1.
cat var nib ‘ Value in range 0 to 15.
dog var byte ‘ Value in range 0 to 255.
rhino var word ‘ Value in range 0 to 65535.
A variable should be given the smallest size that will hold the largest
value that might ever be stored in it. If you need a variable to hold the
on/off status (1 or 0) of switch, use a bit. If you need a counter for a
FOR/NEXT loop that will count from 1 to 10, use a nibble. And so on.