Specifications
BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 219
2
If you assign a value to a variable that exceeds its size, the excess bits
will be lost. For example, suppose you use the nibble variable cat from
the example above and write cat = 91 (%1011011 binary), what will cat
contain? It will hold only the lowest 4 bits of 91—%1011 (11 decimal).
You can also define multipart variables called arrays. An array is a
group of variables of the same size, and sharing a single name, but
broken up into numbered cells. You can define an array using the fol-
lowing syntax:
symbol VAR size(n)
where symbol and size are the same as for normal variables. The new
element, (n), tells PBASIC how many cells you want the array to have.
For example:
myList var byte(10) ‘ Create a 10-byte array.
Once an array is defined, you can access its cells by number. Number-
ing starts at 0 and ends at n–1. For example:
myList(3) = 57
debug ? myList(3)
The debug instruction will display 57. The real power of arrays is that
the index value can be a variable itself. For example:
myBytes var byte(10) ‘ Define 10-byte array.
index var nib ‘ Define normal nibble variable.
For index = 0 to 9 ‘ Repeat with index= 0,1,2...9
myBytes(index)= index*13 ‘ Write index*13 to each cell of array.
Next
For index = 0 to 9 ‘ Repeat with index= 0,1,2...9
debug ? myBytes(index) ‘ Show contents of each cell.
Next
stop
If you run this program, Debug will display each of the 10 values stored
in the cells of the array: myBytes(0) = 0*13 = 0, myBytes(0) = 1*13 = 13,
myBytes(2) = 2*13 = 26...myBytes(9) = 9*13 = 117.










