11.23 itemcount()

This function returns the number of indexed values in a collection. The default value(s) are excluded from that number. Together with indexat() and valueat() it is thus easy to loop through any collection.

Typically, countof() and itemcount() return the same result for values of the data types refvec, vector, and list. However, itemcount() offers the more generic use, whereas countof() is better suited for structured, type-adapted use.

Definition

integer itemcount
(
  anyvalue Value input
)

Parameters

anyvalue Value input
This parameter specifies the value for which the number shall be determined.

Return value

0
The passed value is scalar or an empty collection.
1 … 231
Number of values in the collection without the default values.

Example

dialog D

on dialog start
{
  variable matrix Matrix := [
    [0,0] => "-?-",
    [1,1] => "germany",
    [1,2] => "berlin",
    [2,1] => "france"
    /* [2,2] => inherited from default [0,0] */ ];
  variable integer I;
  variable anyvalue Idx;

  /* print the Matrix values [1,1] [1,2] ... [2,2] */
  for I:=1 to itemcount(Matrix) do
    Idx := indexat(Matrix, I);
    print sprintf("%s : %s", Idx, Matrix[Idx]);
  endfor
  exit();
}

Output

"[1,1] : germany"
"[1,2] : berlin"
"[2,1] : france"
"[2,2] : -?-"

See also

Built-in functions countof(), indexat(), valueat()

Method :index()

Attribute .itemcount

C function DM_ValueCount