5: BASIC Stamp Command Reference – LOOKDOWN
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 179
LOOKDOWN Value, ["The quick brown fox"], Result
DEBUG "Value matches item ", DEC Result, " in list"
DEBUG prints, “Value matches item 16 in list” because the character at
index item 16 is "f" in the phrase, “The quick brown fox”.
The examples above show LOOKDOWN 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.
On the BS2, BS2e, BS2sx and BS2p, the LOOKDOWN command can also
use another criteria (other than "equal to") for its list. All of the examples
above use LOOKDOWN’s default comparison operator, =, that searches
for an exact match. The entire list of ComaprisonOps is shown in Table 5.36.
The "greater than" comparison operator (>) is used in the following
example:
Value VAR BYTE
Result VAR NIB
Value = 17
Result = 15
LOOKDOWN Value, >[26, 177, 13, 1, 0, 17, 99], Result
DEBUG "Value greater than item ", DEC Result, " in list"
DEBUG prints, “Value greater than item 2 in list” because the first item the
value 17 is greater than is 13 (which is item 2 in the list). Value is also
greater than items 3 and 4, but these are ignored, because LOOKDOWN
only cares about the first item that matches the criteria. This can require a
certain amount of planning in devising the order of the list. See the demo
program below.
LOOKDOWN comparison operators use unsigned 16-bit math. They will
not work correctly with signed numbers, which are represented internally
as two’s complement (large 16-bit integers). For example, the two’s
complement representation of -99 is 65437. So although -99 is certainly
less than 0, it would appear to be larger than zero to the LOOKDOWN
comparison operators. The bottom line is: Don’t used signed numbers
with LOOKDOWN comparisons.
LOOKDOWN
CAN USE VARIABLES
AND EXPRESSIONS IN THE VALUE LIST
.
2
e
2
sx
2
p
2
U
SING
LOOKDOWN'
S COMPARISON
OPERATORS
.
W
ATCH OUT FOR UNSIGNED MATH
ERRORS WHEN USING THE
COMPARISON OPERATORS
.
Summary of Contents for BASIC Stamp 2e
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...