Positron Compiler Documentation

LookDown

Positron8 · Revision 4.0.6.5 · PDF page 404

Variable = LookDown Index, [ Constant {, Constant…etc } ]

Search constants(s) for index value. If index matches one of the constants, then store the matching constant's position (0-N) in variable. If no match is found, then the variable is unaffected.

Variable is a user define variable that holds the result of the search. Index is the variable/constant being sought. Constant(s),... is a list of values. A maximum of 255 values may be placed between the square brackets, 256 if using an 18F device.

Device = 18F26K40             ' Select the device to compile for
Declare Xtal = 16  ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600   ' Set the Baud rate for HRsout

Dim Value as Byte
Dim MyResult as Byte
Value = 177             ' The value to look for in the list
MyResult = 255          ' Default to value 255
MyResult = LookDown Value, [75,177,35,1,8,29,245]
HRsoutLn "Value matches ", Dec MyResult, " in list"

In the above example, HRsoutLn displays, "Value matches 1 in list" because Value (177) matches item 1 of [75,177,35,1,8,29,245]. Note that index numbers count up from 0, not 1; that is in the list [75,177,35,1,8,29,245], 75 is item 0.

If the value is not in the list, then MyResult is unchanged.

LookDown is similar to the index of a book. You search for a topic and the index gives you the page number. Lookdown searches for a value in a list, and stores the item number of the first match in a variable.

LookDown also supports text phrases, which are basically lists of byte values, so they are also eligible for Lookdown searches:

Dim Value as Byte
Dim MyResult as Byte

Value = 101          ' ASCII "e". the value to look for in the list
MyResult = 255        ' Default to value 255
MyResult = LookDown Value, ["Hello World"]

In the above example, MyResult will hold a value of 1, which is the position of character 'e'

See also : Cdata, Cread, Data, Edata, Eread, Ldata, LookDownL, LookUp, LookUpL, Lread, Read, Restore.

View original PDF page 404Open page in PDFOriginal PDF page 404