ListGetAt Function

Action

Returns a copy of the element at a specified position of a list.

Include file

List.bdh

Syntax

ListGetAt(
   in theList: list,
   in index: number,
   inout retElement: union) : boolean;
Parameter Description
theList List of number, boolean, float or string.
index Index of theList.
retElement Number, boolean, float or string, which contains a copy of the element at position index of theList as an out parameter. Has to conform with the type of theList.

Return value

  • true if successful
  • false otherwise

Example

transaction TAListGetAt
var
  lstNumber: list of number init 10, 20, 30;
  numberElem: number;
  stringElem: string;   
  retVal: boolean; 
begin
  retVal := ListGetAt(lstNumber, 2, numberElem);
  if((retVal = true) and (numberElem = 20)) then
    writeln("ListGetAt worked! Value of numberElem: " + string(numberElem));
  end;
  retVal := ListGetAt(lstNumber, 2, stringElem);
  if(retVal = false) then
    writeln("ListGetAt did not work, the types do not match!"); 
  end;
  retVal := ListGetAt(lstNumber, 4, numberElem);
  if(retVal = false) then
    writeln("ListGetAt did not work. Index does not exist!");
  end;
end TAListGetAt;

Output

ListGetAt worked! Value of numberElem: 20
ListGetAt did not work, the types do not match!
ListGetAt did not work. Index does not exist!