Iterator Object

Applies to TestComplete 15.46, last modified on January 09, 2023

Description

The Iterator object provides a scripting interface to rows of an array stored in a Table variable. To obtain the Iterator object in scripts, use the TableVariable.Iterator property.

Note: The object contains specific methods that let you go through data rows and access column values of the current row.

Members

Example

The code below demonstrates how you can iterate through the rows of an array stored in a Table variable.

JavaScript, JScript

function Test1()
{
  var MyVar, Iterator, ColName, value;
  MyVar = Project.Variables.MyTableVar; 
  Iterator = MyVar.Iterator;
  
  // Initializes the iterator
  Iterator.Reset();
  
  // Iterates through the rows
  while (!Iterator.IsEOF())
  {
    // Returns the column name by its index
    ColName = MyVar.ColumnName(1);
    
    // Retrieves values and posts them to the log    
    value = Iterator.Value(ColName);
    Log.Message(value);  
    
    // Forwards the iterator to the next row
    Iterator.Next();
  }
}

Python

def Test1():
  MyVar = Project.Variables.MyTableVar
  Iterator = MyVar.Iterator
  # Initializes the iterator
  Iterator.Reset()
  # Iterates through the rows 
  while not Iterator.IsEOF():
    # Returns the column name by its index 
    ColName = MyVar.ColumnName[1]
    # Retrieves values and posts them to the log     
    value = Iterator.Value[ColName]
    Log.Message(value)
    # Forwards the iterator to the next row 
    Iterator.Next()

VBScript

Sub Test1
  Set MyVar = Project.Variables.MyTableVar 
  Set Iterator = MyVar.Iterator
  
  ' Initializes the iterator
  Call Iterator.Reset
  
  ' Iterates through the rows
  While Not Iterator.IsEOF
    ' Returns the column name by its index
    Set ColName = MyVar.ColumnName(1)
    
    ' Retrieves values and posts them to the log    
    value = Iterator.Value(ColName)
    Log.Message(value)  
    
    ' Forwards the iterator to the next row
    Iterator.Next
  WEnd
End Sub

DelphiScript

procedure Test1;
var
  MyVar, Iterator, ColName, value: OleVariant;
begin
  MyVar := Project.Variables.MyTableVar; 
  Iterator := MyVar.Iterator;
  
  // Initializes the iterator
  Iterator.Reset();
  
  // Iterates through the rows
  while not Iterator.IsEOF()do
  begin
    //Returns the column name by its index
    ColName := MyVar.ColumnName(1);
    
    // Retrieves values and posts them to the log    
    value := Iterator.Value[ColName];
    Log.Message(value);  
    
    // Forwards the iterator to the next row
    Iterator.Next();
  end;
end;

C++Script, C#Script

function Test1()
{
  var MyVar, Iterator, ColName, value;
  MyVar = Project["Variables"]["MyTableVar"]; 
  Iterator = MyVar["Iterator"];
  
  // Initializes the iterator
  Iterator["Reset"]();
  
  // Iterates through the rows
  while (!Iterator["IsEOF"]())
  {
    // Returns the column name by its index
    ColName = MyVar["ColumnName"](1);
    
    // Retrieves values and posts them to the log    
    value = Iterator["Value"](ColName);
    Log["Message"](value);  
    
    // Forwards the iterator to the next row
    Iterator["Next"]();
  }
}

See Also

Variables of the Table Type
TableVariable Object

Highlight search results