Specifications
BASIC Stamp II
Page 220 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
A word of caution about arrays: If you’re familiar with other BASICs
and have used their arrays, you have probably run into the “subscript
out of range” error. Subscript is another term for the index value. It’s
‘out of range’ when it exceeds the maximum value for the size of the
array. For instance, in the example above, myBytes is a 10-cell array.
Allowable index numbers are 0 through 9. If your program exceeds
this range, PBASIC2 will not respond with an error message. Instead, it
will access the next RAM location past the end of the array. This can
cause all sorts of bugs.
If accessing an out-of-range location is bad, why does PBASIC2 allow
it? Unlike a desktop computer, the BS2 doesn’t always have a display
device connected to it for displaying error messages. So it just contin-
ues the best way it knows how. It’s up to the programmer (you!) to
prevent bugs.
Another unique property of PBASIC2 arrays is this: You can refer to
the 0th cell of the array by using just the array’s name without an in-
dex value. For example:
myBytes var byte(10) ‘ Define 10-byte array.
myBytes(0) = 17 ‘ Store 17 to 0th cell.
debug ? myBytes(0) ‘ Display contents of 0th cell.
debug ? myBytes ‘ Also displays contents of 0th cell.
This works with the string capabilities of the Debug and Serout
instructions. A string is a byte array used to store text. A string must
include some indicator to show where the text ends. The indicator can
be either the number of bytes of text, or a marker (usually a byte con-
taining 0; also known as a null) located just after the end of the text.
Here are a couple of examples:
‘ Example 1 (counted string):
myText var byte(10) ‘ An array to hold the string.
myText(0) = “H”:myText(1) = “E” ‘ Store “HELLO” in first 5 cells...
myText(2) = “L”:myText(3) = “L”
myText(4) = “0”:myText(9) = 5 ‘ Put length (5) in last cell*
debug str myText\myText(9) ‘ Show “HELLO” on the PC screen.










