BASIC stamp manual v2.2

LOOKUP – BASIC Stamp Command Reference
Page 278 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
index VAR Byte
result VAR Byte
index = 3
result = 255
LOOKUP index, [26, 177, 13, 1, 0, 17, 99], result
DEBUG "Item ", DEC index, " is: ", DEC result
In this example, DEBUG prints “Item 3 is: 1.” Note that the first location
number is 0. In the list above, item 0 is 26, item 1 is 177, etc.
If index is beyond the end of the list, the result variable is unchanged. In
the example above, if index were greater than 6, the message would have
reported the result to be 255, because that’s what result contained before
LOOKUP executed.
Don’t forget that text phrases are just lists of byte values, so they too are
eligible for LOOKUP searches, as in this example:
SYMBOL index = B2
SYMBOL result = B3
index = 16
result = " "
LOOKUP index, ("The quick brown fox"), result
DEBUG @result
-- or --
index VAR Byte
result VAR Byte
index = 16
result = " "
LOOKUP index, ["The quick brown fox"], result
DEBUG ASC ? result
DEBUG prints, “Result = 'f' ” because the character at index item 16 is "f"
in the phrase, “The quick brown fox”.
The examples above show LOOKUP working with lists of constants, but it
also works with variables and expressions also. Note, however, that
expressions are not allowed as argument on the BS1.
THE INDEX NUMBER OF THE FIRST ITEM IS
0, NOT 1.
LOOKUP
CAN USE VARIABLES AND
EXPRESSIONS IN THE VALUE LIST
.
U
SING TEXT IN THE VALUE LIST.
All
2
All
2
1