ArrayLocate

Searches an array for an element that matches a value.

Syntax:

ArrayLocate( array, value, [sub1, [sub2, [sub3, [sub4, [sub5]]]]] )

Parameters:

(a) array: specifies an array.

(s) value: case sensitive value to search for in "array".

(i) sub1: [optional] subscript of first element (dimension 1) to search. The default is zero.

(i) sub2: [optional] subscript of first element (dimension 2) to search. The default is zero.

(i) sub3: [optional] subscript of first element (dimension 3) to search. The default is zero.

(i) sub4: [optional] subscript of first element (dimension 4) to search. The default is zero.

(i) sub5: [optional] subscript of first element (dimension 5) to search. The default is zero.

Returns:

(a) array: a single dimensioned array with one element per dimension of the searched array. Each element of the returned array holds one subscript of the element with the value when found and -1 if the value is not found.

 

Note: The least significant array dimension can be incremented one past its maximum and ArrayLocate knows what you mean. It automagically adjusts all dimensions to start one element past the previously found element.

Examples:

strList = 'a b c A B C 1 0 -1'
value = 'C' ; (uppercase letter C)
sub1 = 2 ; Start on the third element of the first dimension
; Create an array to search
arrList = Arrayize( strList, ' ' )
; Search the array starting on the third element of the first dimension
arrRslt = ArrayLocate(arrList,value,sub1)
; Read result from the array
result = arrRslt[0]
; Display results ( expect 5 )
Pause( 'ArrayLocate of value: ' : value, 'Element number: ' : result )
Exit
 

 
; find all occurrences of "fred" in a two dimensional array arr = ArrDimension(3,2) arr[0,0] = "fred" arr[0,1] = "fred" arr[1,0] = "john" arr[1,1] = "bill" arr[2,0] = "tom" arr[2,1] = "fred" res = ArrDimension(2) res[0] = 0 res[1] = 0 While 1    res = ArrayLocate(arr,"fred",res[0],res[1])    If res[0] == -1 Then Break    Message(res[0],res[1])    res[1] = res[1] + 1 ; skip that one EndWhile
 

 
; To find name and city for particular id. array = ArrDimension (25, 3) array[1, 0]  = "WN001"     ; id array[1, 1]  = "fred"      ; name array[1, 2]  = "amsterdam" ; city array[2, 0]  = "WN002"     ; id array[2, 1]  = "pete"      ; name array[2, 2]  = "rotterdam" ; city array[7, 0]  = "WN007"     ; id array[7, 1]  = "detlev"    ; name array[7, 2]  = "wuppertal" ; city array[24, 0] = "WN024"     ; id array[24, 1] = "john"      ; name array[24, 2] = "new york"  ; city lookfor = "WN007" arrResult = ArrayLocate (array, lookfor ) ; arrResult = [7,0] id = array [arrResult[0], arrResult[1]] name = array [arrResult[0], arrResult[1] + 1] city = array [arrResult[0], arrResult[1] + 2] Pause( 'Results', id: @LF : name : @LF : city )
 
See Also:

Arrays, ArrayFileGet, ArrayFileGetCsv, ArrayFilePut, ArrayFilePutCsv, ArrayFromStr, ArrayInsert,  ArrayItemize, Arrayize, ArrayLocate, ArrayRedim, ArrayRemove, ArrayReverse, ArraySearch, ArraySort, ArraySwapElements, ArrayToStr, ArrDimension, ArrInfo, ArrInitalize, Drop