Find in array

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 3


Find in array (array; value{; start}) Number

ParameterTypeDescription
arrayArrayArray to search
valueExpressionValue of same type to search in the array
startNumberElement at which to start searching
Function resultNumberNumber of the first element in array
that matches value

Description

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.

Examples

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 ELEMENT ($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)

2. 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

See Also

DELETE ELEMENT, INSERT ELEMENT, Size of array.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next