4D v14.3Find in array |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v14.3
Find in array
|
Find in array ( array ; value {; start} ) -> Function result | ||||||||
Parameter | Type | Description | ||||||
array | Array |
![]() |
Array to search | |||||
value | Expression |
![]() |
Value of same type to search in the array | |||||
start | Longint |
![]() |
Element at which to start searching | |||||
Function result | Longint |
![]() |
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
Note: This example uses the selected element of the array. Keep in mind that the selected element is not meaningful if the array contains more than 32,767 elements (see Arrays and Form Objects). In this case, you need to use a longint variable to store the result of Find in array.
Product: 4D
Theme: Arrays
Number:
230
Created: < 4D v6
DELETE FROM ARRAY
INSERT IN ARRAY
Size of array
4D Language Reference ( 4D v11 SQL Release 6)
4D Language Reference ( 4D v12.4)
4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v13.5)
4D Language Reference ( 4D v14.3)
Parent of : Find in array ( 4D v14 R4)