LookDown
Syntax
Assignment Variable = LookDown Index, [ Constant {, Constant…etc } ]
Overview
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.
Parameters
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. Assignment Variable is a user define variable that holds the result of the search.
Example
Device = 24HJ128GP502 ' Select the device to compile for
Declare Xtal = 16
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]
Print "Value matches ", Dec MyResult, " in list"
In the above example, Print 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.
Notes.
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:
Device = 24HJ128GP502 ' Select the device to compile for
Declare Xtal = 16
Dim Value as Byte = 101 ' ASCII "e". the value to look for in the list
Dim MyResult as Byte = 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 : Dim, cPtr8, cPtr16, cPtr24, cPtr32, Cread8, Cread16, Cread24, Cread32, Edata, Eread, LookDownL, LookUp, LookUpL.
