KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Performing a query in an array
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: March 7, 2003
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Compatibility: Version 6.7.x and 6.8.x

Here is a project method that performs a query in an array.

  ` Project Method: Query_in_array

C_POINTER($1;$2;$targetArray;$findElem)
$targetArray:=$1
$findElem:=$2

C_LONGINT($foundAt;$count;$lastElem)
$foundAt:=1
$count:=0
Repeat
 $count:=$count+1
 $foundAt:=Find in array($targetArray->;$findElem->;$count)
 If ($foundAt>0)
  DELETE ELEMENT($targetArray->;$count;$foundAt-$count)
 End if
Until ($foundAt<0)

$lastElem:=Size of array($targetArray->)
If ($lastElem>=$count)
 DELETE ELEMENT($targetArray->;$count;($lastElem-$count)+1)
End if

If no matching element has been found, the array is reduced to the array of size 0. Otherwise, the array will contain only the matching elements.