AddVariable Method

Applies to TestComplete 15.70, last modified on December 17, 2024

The object-driven testing (ODT) functionality is deprecated. Do not use it to create new tests. It will be removed from the product in one of the future releases. As an alternative, you can create custom classes in your scripts. For more information, see Alternatives to the ODT functionality.

Description

The Group.AddVariable method adds a new “ordinary” or object variable to the group. “Ordinary” means that this variable can store only ordinary values: integers, strings, dates, etc. This variable cannot store an array that was created via the ODT project item. To create a variable that will store such an array, use the AddVarOfArrayType method. To create an object variable, you can also use the AddVarOfClassType method.

Declaration

GroupObj.AddVariable(Name, Value)

GroupObj An expression, variable or parameter that specifies a reference to a Group object
Name [in]    Required    String    
Value [in]    Optional    Variant    
Result Variant

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Name

Specifies the variable name. The variable name must be unique within the group. If the group contains another variable with the specified name, an error occurs.

Value

Specifies the variable value. You can omit the Value parameter and set the variable value later in your script. If you pass an object as this parameter, you will create an object variable.

Result Value

The new variable.

Example

The code below creates a new data group and then adds new variables to it.

JavaScript, JScript

function AddVariable()
{
  // Creates a data group
  var Group = ODT.Data.AddGroup("NewGroup");
  // Adds variables to the group
  Group.AddVariable("Variable_1", "Variable_Value");
  Group.AddVariable("Variable_2", 456);
  // Adds a variable of the array type
  var Variable = Group.AddVarOfArrayType("Variable_3");
  // Adds new items to the created variable
  Variable.AddItem(123);
  Variable.AddItem("My_Text");
  //...
}

VBScript

Sub AddVariable

  ' Creates a data group
  Set Group = ODT.Data.AddGroup("NewGroup")
  ' Adds variables to the group
  Call Group.AddVariable("Variable_1", "Variable_Value")
  Call Group.AddVariable("Variable_2", 456)
  ' Adds a variable of the array type
  Set Variable = Group.AddVarOfArrayType("Variable_3")
  ' Adds new items to the created variable
  Variable.AddItem(123)
  Variable.AddItem("My_Text")
  '...
End Sub

DelphiScript

function AddVariable;
var Group, Variable;
begin

  // Creates a data group
  Group := ODT.Data.AddGroup('NewGroup');
  // Adds variables to the group
  Group.AddVariable('Variable_1', 'Variable_Value');
  Group.AddVariable('Variable_2', 456);
  // Adds a variable of the array type
  Variable := Group.AddVarOfArrayType('Variable_3');
  // Adds new items to the created variable
  Variable.AddItem(123);
  Variable.AddItem('My_Text');
  //...

end;

C++Script, C#Script

function AddVariable()
{
  // Creates a data group
  var Group = ODT["Data"]["AddGroup"]("NewGroup");
  // Adds variables to the group
  Group["AddVariable"]("Variable_1", "Variable_Value");
  Group["AddVariable"]("Variable_2", 456);
  // Adds a variable of the array type
  var Variable = Group["AddVarOfArrayType"]("Variable_3");
  // Adds new items to the created variable
  Variable["AddItem"](123);
  Variable["AddItem"]("My_Text");
  //...
}

See Also

AddVarOfArrayType Method
AddVarOfClassType Method
DeleteVariable Method
Variables Property

Highlight search results