This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v20 R7
Count in array

Count in array 


 

Count in array ( array ; value ) -> Function result 
Parameter Type   Description
array  Array in Array where count should occur
value  Expression in Value to count
Function result  Longint in Number of instances found

The Count in array command returns the number of times value is found in array.

This command can be used with the following array types: Text, number, Date, Pointer, Object, and Boolean. The array and value parameters must be the same type or compatible.

Note: With Object arrays, you can only use object references in the value parameter. 

If no element in array matches value, the command returns 0.

The following example allows displaying the number of selected lines in a list box:

  //tBList is the name of a List box column array
 ALERT(String(Count in array(tBList;True))+" line(s) selected in the list box")

You want to count object references in an object array:

 ARRAY OBJECT($objects;100)
 $o1:={a10;b"xyz"}
 $o2:={a10;b"xyz"}
 
 $objects{20}:=$o1
 $objects{21}:=$o1
 $objects{22}:=$o1
 
 var $n : Integer
 
 $n:=Count in array($objects;$o1// n = 3 
 $n:=Count in array($objects;$o2// n = 0



See also 

Find in array
Find in sorted array

 
PROPERTIES 

Product: 4D
Theme: Arrays
Number: 907

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D 2004

 
ARTICLE USAGE

4D Language Reference ( 4D v20 R7)