11.7 countof()

This function returns the size of a collection. This is usually the highest index value.

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

anyvalue countof
(
  anyvalue Value input
)

Parameters

anyvalue Value input
This parameter specifies the value for which the indexing type or the highest index value shall be determined.

Return value

nothing
The passed value is scalar.
1 … 231
Highest index of the passed list (data types list, vector, refvec).
[0 … 65535,0 … 65535]
Highest index of the passed matrix.
anyvalue
Data type of the index of the passed associative array (data type hash).

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 Row, Col;
  variable anyvalue Count, Idx;

  /* print the Matrix values [0,0] [0,1] ... [2,2] */
  Count := countof(Matrix);
  for Row:=0 to first(Count) do
    for Col:=0 to second(Count) do
      Idx := [Row,Col];
      print sprintf("%s : %s", Idx, Matrix[Idx]);
    endfor
  endfor
  exit();
}

See also

Built-in functions itemcount(), valueat()

Method :index()

Attribute .count

C function DM_ValueCount