4: BASIC Stamp Architecture – Constants and Expressions
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 57
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 = 3 ‘ Number of 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
1
2
e
2
sx
2
p
2
1
2
e
2
sx
2
p
2
Содержание BASIC Stamp 2e
Страница 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...