BASIC stamp manual v2.2

LOOKDOWN – BASIC Stamp Command Reference
Page 274 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
to the LOOKDOWN comparison operators. The bottom line is: Don’t used
signed numbers with LOOKDOWN comparisons.
ComparisonOp Symbol Description
= Find the first value Target is equal to
<> Find the first value Target is not equal to
> Find the first value Target is greater than
< Find the first value Target is less than
>= Find the first value Target is greater than or equal to
<= Find the first value Target is less than or equal to
Table 5.53: LOOKDOWN
Comparison Operators.
A common application for LOOKDOWN is to use it in conjunction with
the BRANCH, ON...GOTO, or ON...GOSUB commands to create selective
jumps based on a simple variable input:
' {$PBASIC 2.5}
cmd VAR Byte
DO
DEBUG CLS, "Enter cmd (SLMH): "
DEBUGIN cmd
LOOKDOWN cmd, ["SLMH"], cmd
ON cmd GOSUB _Stop, _Low, _Medium, _High
IF cmd > 3 THEN DEBUG CLS, "Command not in list"
PAUSE 2000
END
LOOP
_Stop:
DEBUG CLS, "Stop"
RETURN
_Low:
DEBUG CLS, "Low"
RETURN
_Medium:
DEBUG CLS, "Medium"
RETURN
_High:
DEBUG CLS, "High"
RETURN
In this example, the program waits for a key. Here's what happens when
"M" is pressed and cmd contains “M” (ASCII 77). LOOKDOWN finds that
this is item 2 of a list of one-character commands and stores 2 into cmd.
ON...GOSUB then goes to item 2 of its list, which is the program label
USING LOOKDOWN WITH BRANCH ,
ON...GOTO OR ON...GOSUB TO JUMP
BASED ON VALUES
.
All
2