11.20 indexat()

This function returns the index of a collection at a specific position. The allowed positions are 1 … itemcount() and thus allow a loop through all indexed values.

For values of type list, refvec and vector, the position is identical to the actual index. For a hash value, there is no defined order of the indexes returned. For matrix values, the increasing positions are mapped in a sequence where all ( column) values of a row are arranged in ascending order.

The function returns an error (fail) if the position is outside the allowed range or if the Value parameter is not a collection.

Definition

anyvalue indexat
(
  anyvalue Value input,
  integer  Pos   input
)

Parameters

anyvalue Value input
This parameter specifies the value list from which the index shall be queried.
integer Pos input
Position for which the index value shall be determined.

Return value

Index value at the position passed as parameter.

Example

dialog D

on dialog start
{
  variable matrix Matrix := [
    [0,0] => "-?-",
    [1,1] => "germany",
    [1,2] => "berlin",
    [2,1] => "france" ];
  variable integer Pos;

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

See also

Built-in functions .itemcount, keys(), valueat()

Method :index()

C function DM_ValueIndex