BASIC Stamp Architecture – Defining Arrays
Page 52
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
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 elements of the array: MyBytes(0) = 0*13 = 0, MyBytes(0) = 1*13 =
13, MyBytes(2) = 2*13 = 26 ... MyBytes(9) = 9*13 = 117.
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 is
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,
PBASIC will not respond with an error message. Instead, it will access the
next RAM location past the end of the array. If you are not careful about
this, it can cause all sorts of bugs.
If accessing an out-of-range location is bad, why does PBASIC allow it?
Unlike a desktop computer, the BASIC Stamp doesn’t always have a
display device connected to it for displaying error messages. So it just
continues the best way it knows how. It’s up to the programmer (you!) to
prevent bugs.
Another unique property of PBASIC arrays is this: You can refer to the 0th
cell of the array by using just the array’s name without an index 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.
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
Содержание BASIC Stamp 1
Страница 1: ...BASIC Stamp Programming Manual Version 2 0c...
Страница 30: ...Introduction to the BASIC Stamps Page 28 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 90: ...BUTTON BASIC Stamp Command Reference Page 88 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 118: ...END BASIC Stamp Command Reference Page 116 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 128: ...FREQOUT BASIC Stamp Command Reference Page 126 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 196: ...NAP BASIC Stamp Command Reference Page 194 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 206: ...OWIN BASIC Stamp Command Reference Page 204 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 214: ...OWOUT BASIC Stamp Command Reference Page 212 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 216: ...PAUSE BASIC Stamp Command Reference Page 214 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 226: ...POLLMODE BASIC Stamp Command Reference Page 224 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 232: ...POLLOUT BASIC Stamp Command Reference Page 230 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 236: ...POLLRUN BASIC Stamp Command Reference Page 234 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 240: ...POLLWAIT BASIC Stamp Command Reference Page 238 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 262: ...RCTIME BASIC Stamp Command Reference Page 260 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 274: ...RUN BASIC Stamp Command Reference Page 272 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 310: ...SEROUT BASIC Stamp Command Reference Page 308 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 324: ...STOP BASIC Stamp Command Reference Page 322 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...