Inlist

Inlist function (Is value in list?) by the model it exists in FoxPro. //Many thanks to uncleBen for suggesting fix for spaces in list//

Sometimes it is shorter (and clearer) to write code format="thinbasic" if inlist(x, "2 12 44") then ... code then code format="thinbasic" if x = 2 OR x = 12 OR x = 44 then ... code

code format="thinbasic" 'example: x = 2 print inlist(x, "2 12  44  5") 'In list, prints 1 print inlist(x, "0 5 12")      'Not In list, prints 0

' 'Inlist function (Is value in list?). ' Returns 0/1 (to be used in logic expressions) function inlist(aVal, list$) list$ = " "+list$+" " inlist = (instr(list$, " "+str$(aVal)+" ")<>0) end function code