VariableCount Property

Applies to TestComplete 14.10, last modified on June 5, 2019

Description

Use the Variables.VariableCount property to get the total number of variables in the Variables_Obj collection.

Declaration

VariablesObj.VariableCount

Read-Only Property Integer
VariablesObj An expression, variable or parameter that specifies a reference to a Variables object

Applies To

The property is applied to the following object:

Property Value

The total number of variables in the collection.

Example

The following code snippet demonstrates how to iterate through project suite variables and post their names and values to the test log.

JavaScript, JScript

function VariablesCount()
{

  var Variables, Count, VarName, VarValue;

  // Obtains the Variables object
  Variables = ProjectSuite.Variables;

  // Obtains the total number of variables
  Count = Variables.VariableCount;

  // Iterates through the variables
  for (var i = 0; i < Count; i++)
    {
    // Obtains a variable's name
    VarName = Variables.GetVariableName(i);
    // Obtains the variable's value
    VarValue = aqConvert.VarToStr(Variables.VariableByName(VarName));
    Log.Message("Variable: " + VarName + " Value: " + VarValue);
    }

}

Python

def VariablesCount():

  # Obtains the Variables object
  Variables = ProjectSuite.Variables

  # Obtains the total number of variables
  Count = Variables.VariableCount

  # Iterates through the variables
  for i in range (0, Count):
    # Obtains a variable's name
    VarName = Variables.GetVariableName(i)
    # Obtains the variable's value
    VarValue = aqConvert.VarToStr(Variables.VariableByName[VarName])
    Log.Message("Variable: " + str(VarName) + " Value: " + str(VarValue))

VBScript

Sub VariablesCount

  Dim Variables, Count, VarName, VarValue

  ' Obtains the Variables object
  Set Variables = ProjectSuite.Variables

  ' Obtains the total number of variables
  Count = Variables.VariableCount

  ' Iterates through the variables
  For i = 0 To Count - 1
    ' Obtains a variable's name
    VarName = Variables.GetVariableName(i)
    ' Obtains the variable's value
    VarValue = aqConvert.VarToStr(Variables.VariableByName(VarName))
    Log.Message("Variable: " & VarName & " Value: " & VarValue)
  Next

End Sub

DelphiScript

procedure VariablesCount();
var Variables, Count, VarName, VarValue, i;
begin
  // Obtains the Variables object
  Variables := ProjectSuite.Variables;

  // Obtains the total number of variables
  Count := Variables.VariableCount;

  // Iterates through the variables
  for i := 0 to Count -1 do
    begin
    // Obtains a variable's name
    VarName := Variables.GetVariableName(i);
    // Obtains the variable's value
    VarValue := aqConvert.VarToStr(Variables.VariableByName[VarName]);
    Log.Message('Variable: ' + VarName + ' Value: ' + VarValue);
    end;

end;

C++Script, C#Script

function VariablesCount()
{

  var Variables, Count, VarName, VarValue;

  // Obtains the Variables object
  Variables = ProjectSuite["Variables"];

  // Obtains the total number of variables
  Count = Variables["VariableCount"];

  // Iterates through the variables
  for (var i = 0; i < Count; i++)
    {
    // Obtains a variable's name
    VarName = Variables["GetVariableName"](i);
    // Obtains the variable's value
    VarValue = aqConvert["VarToStr"](Variables["VariableByName"](VarName));
    Log["Message"]("Variable: " + VarName + " Value: " + VarValue);
    }

}

See Also

Variables.GetVariableName.

Highlight search results