AddColumn Method

Applies to TestComplete 14.30, last modified on November 21, 2019

Description

The TableVariable.AddColumn method lets you add a new column to the array represented by the TableVariable object.

Declaration

TableVariableObj.AddColumn(ColumnName)

TableVariableObj An expression, variable or parameter that specifies a reference to a TableVariable object
ColumnName [in]    Optional    String    
Result Integer

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

ColumnName

Specifies the name of the column to be added to the array.

Result Value

An integer number that indicates the index of the newly created column.

Remarks

Table variables are always temporary. TestComplete will not save any changes you make to a Table variable between test runs. See Variables of the Table Type.

Example

The code below demonstrates how you can add columns to and remove them from the array and how you can post the total number of columns and rows in the array to the log.

JavaScript, JScript

function Test1()
{
  var MyVar;
  MyVar = Project.Variables.MyTableVar;
   
  // Adds a new column to the array
  MyVar.AddColumn("LastColumn");
  
  // Posts the total number of rows and columns in the array
  Log.Message("The total number of columns in the array: " + MyVar.ColumnCount);
  Log.Message("The total number of rows in the array: " + MyVar.RowCount);

  // Removes the last column
  MyVar.RemoveColumn("LastColumn");  
}

Python

def Test1():
  MyVar = Project.Variables.MyTableVar
  # Adds a new column to the array 
  MyVar.AddColumn("LastColumn")
  # Posts the total number of rows and columns in the array 
  Log.Message("The total number of columns in the array: " + str(MyVar.ColumnCount))
  Log.Message("The total number of rows in the array: " + str(MyVar.RowCount))
  # Removes the last column
  MyVar.RemoveColumn("LastColumn")

VBScript

Sub Test1
  Set MyVar = Project.Variables.MyTableVar
   
  ' Adds a new column to the array
  Call MyVar.AddColumn("LastColumn")
  
  ' Posts the total number of rows and columns in the array
  Log.Message("The total number of columns in the array: " & MyVar.ColumnCount)
  Log.Message("The total number of rows in the array: " & MyVar.RowCount)

  ' Removes the last column
  Call MyVar.RemoveColumn("LastColumn")  
End Sub

DelphiScript

procedure Test1;
var MyVar: OleVariant;
begin
  MyVar := Project.Variables.MyTableVar;
   
  // Adds a new column to the array
  MyVar.AddColumn('LastColumn');
  
  // Posts the total number of rows and columns in the array
  Log.Message('The total number of columns in the array: ' + VarToStr(MyVar.ColumnCount));
  Log.Message('The total number of rows in the array: ' + VarToStr(MyVar.RowCount));

  // Removes the last column
  MyVar.RemoveColumn('LastColumn');  
end;

C++Script, C#Script

function Test1()
{
  var MyVar;
  MyVar = Project["Variables"]["MyTableVar"];
   
  // Adds a new column to the array
  MyVar["AddColumn"]("LastColumn");
  
  // Posts the total number of rows and columns in the array
  Log["Message"]("The total number of columns in the array: " + MyVar["ColumnCount"]);
  Log["Message"]("The total number of rows in the array: " + MyVar["RowCount"]);

  // Removes the last column
  MyVar["RemoveColumn"]("LastColumn");  
}

See Also

Variables of the Table Type
RemoveColumn Method
ColumnCount Property
ColumnName Property

Highlight search results