AddColumn Method

Applies to TestComplete 15.63, last modified on April 23, 2024

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 shows how you can add columns to the array:

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