ColumnIndex Property

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

Use the ColumnIndex property to obtain the index of a column stored in the Table project element that corresponds to the Table object. You can then use this index to obtain or set stored data with the Values and ValuesSelected properties.

Declaration

TableObj.ColumnIndex(ColumnName)

Read-Only Property Integer
TableObj An expression, variable or parameter that specifies a reference to a Table object
ColumnName [in]    Required    String    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

ColumnName

Specifies the name of the desired column as it is displayed in the Table Element editor.

Property Value

Index of the specified column. The column index is zero-based, that is, if the column is first, its index is 0, if the column is second, its index is 1 and so on.

If the Table element does not contain a column with the specified name, the property returns -1.

Remarks

If you use Python or DelphiScript, you should enclose the parameter of the ColumnIndex property in square brackets: ColumnIndex[ColumnName].

Example

The following code snippet obtains the column’s index by its name and excludes the values stored in this column from the comparison.

JavaScript

function Test()
{

  var Table, RowCount, Column;
  // Obtains the Table element
  Table = Tables.OrdersTable;
  // Obtains the column’s index
  Column = Table.ColumnIndex("Customer Name");
  // Obtains the total number of rows in the table
  RowCount = Table.RowCount;
  // Iterates through the stored rows
  for (let i = 0; i <RowCount; i++)
    Table.$set("ValuesSelected", i, Column, false);
  // Compares the stored values
  Table.Compare(true, lmError);

}

JScript

function Test()
{

  var Table, RowCount, i, Column;
  // Obtains the Table element
  Table = Tables.OrdersTable;
  // Obtains the column’s index
  Column = Table.ColumnIndex("Customer Name");
  // Obtains the total number of rows in the table
  RowCount = Table.RowCount;
  // Iterates through the stored rows
  for (i = 0; i <RowCount; i++)
    Table.ValuesSelected(i, Column) = false;
  // Compares the stored values
  Table.Compare(true, lmError);

}

Python

def Test():  
  # Obtains the total number of rows in the table
  RowCount = Tables.OrdersTable.RowCount
  # Iterates through the stored rows
  secondIndex = Tables.OrdersTable.ColumnIndex["Customer Name"]
  for i in range(0, RowCount):
    Tables.OrdersTable.ValuesSelected[i, secondIndex] = False
  # Compares the stored values
  Tables.OrdersTable.Compare(True, lmError);

VBScript

Sub Test

  Dim Table, RowCount, i, Column
  ' Obtains the Table element
  Set Table = Tables.OrdersTable
  ' Obtains the column’s index
  Column = Table.ColumnIndex("Customer Name")
  ' Obtains the total number of rows in the table
  RowCount = Table.RowCount
  ' Iterates through the stored rows
  For i = 0 to RowCount - 1
    Table.ValuesSelected(i, Column) = False
  Next
  ' Compares the stored values
  Call Table.Compare(True, lmError)

End Sub

DelphiScript

procedure Test();
var Table, RowCount, i, Column;
begin

  // Obtains the Table element
  Table := Tables.OrdersTable;
  // Obtains the column’s index
  Column := Table.ColumnIndex['Customer Name'];
  // Obtains the total number of rows in the table
  RowCount := Table.RowCount;
  // Iterates through the stored rows
  for i := 0 to RowCount - 1 do
    Table.ValuesSelected[i, Column] := false;
  // Compares the stored values
  Table.Compare(true, lmError);

end;

C++Script, C#Script

function Test()
{

  var Table, RowCount, i, Column;
  // Obtains the Table element
  Table = Tables["OrdersTable"];
  // Obtains the column’s index
  Column = Table["ColumnIndex"]("Customer Name");
  // Obtains the total number of rows in the table
  RowCount = Table["RowCount"];
  // Iterates through the stored rows
  for (i = 0; i <RowCount; i++)
    Table["ValuesSelected"](i, Column) = false;
  // Compares the stored values
  Table["Compare"](true, lmError);

}

See Also

About Table Checkpoints
About Tables Collection
Values Property
ValuesSelected Property
RowCount Property

Highlight search results