FIND Statement
Locates the position (attribute, value or subvalue) of a string or value in a dynamic array.
Syntax
FIND value IN dynArray{,occurrence} SETTING attrVar{,valVar{,subvalVar}} [THEN statement(s) | ELSE statement(s)]
Syntax elements
value An expression that evaluates to the string or value being searched for.
dynArray The name of the dynamic array in which to search.
occurrence The number of the occurrence of the element being searched for in dynArray.
If occurrence is not specified, it defaults to 1.
attrVar A variable that is set to the attribute position where the element is found.
valVar A variable that is set to the value position where the element is found; if the element is found in an attribute that has no values, valVar and subvalVar will both be set to 0.
subvalVar A variable that is set to the subvalue position where the element is found; if the element is found in an attribute or value that has no subvalues, subvalVar will be set to 0.
statement(s) Either a THEN or ELSE clause (or both). A statement must be included. The THEN clause is executed if the FIND is successful; otherwise the ELSE clause is executed.
Operation
FIND returns the attribute and, if specified, the value and subvalue in which the element is found.
Case insensitivity
If data case insensitive mode is selected (see Case Sensitivity), case is ignored when searching dynArray for value.
Examples
Example #1
DYNARR = "A":@AM:"B":@AM:"C":@AM:"D":@AM:"E":@AM:"F":@AM:"G":@AM:"A":@AM:"B":@AM:"C" FIND "A" IN DYNARR,2 SETTING X ELSE PRINT "NOT FOUND"; STOP
Finds the second occurrence of the element A in dynamic array DYNARR. Sets X to a number indicating the position of that attribute. In this example, X = 8 (the second occurrence of A in DYNARR is its eighth atribute).
Example #2
ITEM = "24":@AM:"34":@VM:"28":@VM:"31":@AM:"29":@VM:"22":@VM:"21" X=29 FIND X IN ITEM,1 SETTING A,B ELSE PRINT "NOT FOUND"; STOP PRINT A,B
Finds the multivalue equal to 29 in attribute A, value B and prints A and B. In this example, A=3 and B=1.
Example #3
ARR = "44":@AM:"88":@AM:"6":@VM:"2":@VM:"7":@SVM:"3":@SVM:"2":@AM:"8":@AM:"99" FIND 3 IN ARR,1 SETTING A,B,C ELSE PRINT "CAN'T FIND"; STOP PRINT A,B,C
Finds numeric literal 3 in attribute 3, value 3, subvalue 2 of dynamic array ARR and prints the contents of A, B and C (3, 3 and 2).
Example #4
ARR = "44":@AM:"88":@AM:"6":@VM:"2":@AM:"8":@AM:"99" FIND 6 IN ARR,1 SETTING A,B,C ELSE PRINT "CAN'T FIND"; STOP PRINT A,B,C
Finds numeric literal 6 in attribute 3, value 1 of dynamic array ARR and prints the contents of A, B and C (3, 1 and 0). The value in C is set to 0 as there are no subvalues in attribute 3, value 1.
Example #5
ARR = "44":@AM:"88":@AM:"6":@AM:"8":@AM:"99" FIND 8 IN ARR,1 SETTING A,B,C ELSE PRINT "CAN'T FIND"; STOP PRINT A,B,C
Finds numeric literal 8 in attribute 4 of dynamic array ARR and prints the contents of A, B and C (4, 0 and 0). The values of both B and C are set to 0 as there are no values and therefore no subvalues in attribute 4.