4D v13.4

Find in array

Home

 
4D v13.4
Find in array

Find in array 


 

Find in array ( array ; value {; start} ) -> Function result 
Parameter Type   Description
array  Array in Array to search
value  Expression in Value of same type to search in the array
start  Longint in Element at which to start searching
Function result  Longint in Number of the first element in array that matches value

The Find in array command returns the number of the first element in array that matches value.

Find in array can be used with Text, String, Numeric, Date, Pointer, and Boolean arrays. The array and value parameters must be of the same type.

If no match is found, Find in array returns –1.

If start is specified, the command starts searching at the element number specified by start. If start is not specified, the command starts searching at element 1.

The following project method deletes all empty elements from the string or text array whose pointer is passed as parameter:

  ` CLEAN UP ARRAY project method
  ` CLEAN UP ARRAY ( Pointer )
  ` CLEAN UP ARRAY ( -> Text or String array )
 
 C_POINTER($1)
 Repeat
    $vlElem:=Find in array($1->;"")
    If($vlElem>0)
       DELETE FROM ARRAY($1->;$vlElem)
    End if
 Until($vlElem<0)

After this project method is implemented in a database, you can write:

 ARRAY TEXT(atSomeValues;...)
  ` ...
  ` Do plenty of things with the array
  ` ...
  ` Eliminate empty string elements
 CLEAN UP ARRAY(->atSomeValues)

The following project method selects the first element of an array whose pointer is passed as the first parameter that matches the value of the variable or field whose pointer is passed as parameter:

  ` SELECT ELEMENT project method
  ` SELECT ELEMENT ( Pointer ; Pointer)
  ` SELECT ELEMENT ( -> Text or String array ; -> Text or String variable or field )
 
 $1->:=Find in array($1->;$2->)
 If($1->=-1)
    $1->:=0 ` If no element was found, set the array to no selected element
 End if

After this project method is implemented in a database, you can write:

  ` asGender pop-up menu object method
 Case of
    :(Form event=On Load)
       SELECT ELEMENT(->asGender;->[People]Gender)
 
 End case

 
PROPERTIES 

Product: 4D
Theme: Arrays
Number: 230

 
INDEX

Alphabetical list of commands

 
HISTORY 

Created: < 4D v6

 
SEE ALSO 

DELETE FROM ARRAY
INSERT IN ARRAY
Size of array