GetVariableName Method

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

Description

This method returns the name of the variable specified by its index in the Variables collection. This name can be used to obtain the variable via the Variable.VariableByName property.

Declaration

VariablesObj.GetVariableName(Index)

VariablesObj An expression, variable or parameter that specifies a reference to a Variables object
Index [in]    Required    Integer    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Index

Specifies the variable’s index within the collection. The index is zero-based, so the first variable has index 0, the second - 1 and so on.

Result Value

The string holding the variable name.

Example

The following code snippet obtains project suite variables and posts their properties to the test log.

JavaScript, JScript

function Variables()
{

  var Variables, Count, VarName;

  // Obtains a list of project suite variables
  Variables = ProjectSuite.Variables;
  // Obtains the total number of variables in the project suite
  Count = Variables.VariableCount;

  // Iterates through the project suite variables
  for (var i = 0; i < Count; i++)
    {
    // Obtains a variable's name and posts it to the test log
    VarName = Variables.GetVariableName(i);
    Log.AppendFolder(VarName);

    // Posts the variable’s category to the test log
    Log.Message("Category: " + Variables.GetVariableCategory(i));
    // Posts the variable’s type to the test log
    Log.Message("Type: " + Variables.GetVariableType(i));
    // Posts the variable’s default value to the test log
    Log.Message("Default Value: " + Variables.GetVariableDefaultValue(i));
    // Posts the variable’s description to the test log
    Log.Message("Description: " + Variables.GetVariableDescription(i));

    Log.PopLogFolder();
    }

}

Python

def Variables():

  # Obtains a list of project suite variables
  Variables = ProjectSuite.Variables
  # Obtains the total number of variables in the project suite
  Count = Variables.VariableCount

  # Iterates through the project suite variables
  for i in range (0, Count):
    # Obtains a variable's name and posts it to the test log
    VarName = Variables.GetVariableName(i)
    Log.AppendFolder(VarName)

    # Posts the variable's category to the test log
    Log.Message("Category: " + str(Variables.GetVariableCategory(i)))
    # Posts the variable's type to the test log
    Log.Message("Type: " + str(Variables.GetVariableType(i)))
    # Posts the variable's default value to the test log
    Log.Message("Default Value: " + str(Variables.GetVariableDefaultValue(i)))
    # Posts the variable's description to the test log
    Log.Message("Description: " + str(Variables.GetVariableDescription(i)))

    Log.PopLogFolder()

VBScript

Sub Variables

  Dim Variables, Count, VarName

  ' Obtains a list of project suite variables
  Set Variables = ProjectSuite.Variables
  ' Obtains the total number of variables in the project suite
  Count = Variables.VariableCount

  ' Iterates through the project suite variables
  For i = 0 To Count - 1
    ' Obtains a variable's name and posts it to the test log
    VarName = Variables.GetVariableName(i)
    Log.AppendFolder(VarName)

    ' Posts the variable’s category to the test log
    Log.Message("Category: " & Variables.GetVariableCategory(i))
    ' Posts the variable’s type to the test log
    Log.Message("Type: " & Variables.GetVariableType(i))
    ' Posts the variable’s default value to the test log
    Log.Message("Default Value: " & Variables.GetVariableDefaultValue(i))
    ' Posts the variable’s description to the test log
    Log.Message("Description: " & Variables.GetVariableDescription(i))

    Log.PopLogFolder
  Next

End Sub

DelphiScript

procedure Variables();
var Variables, Count, VarName, i;

begin

  // Obtains a list of project suite variables
  Variables := ProjectSuite.Variables;
  // Obtains the total number of variables in the project suite
  Count := Variables.VariableCount;

  // Iterates through the project suite variables
  for i := 0 to Count - 1 do
    begin
    // Obtains a variable's name and posts it to the test log
    VarName := Variables.GetVariableName(i);
    Log.AppendFolder(VarName);

    // Posts the variable’s category to the test log
    Log.Message('Category: ' + Variables.GetVariableCategory(i));
    // Posts the variable’s type to the test log
    Log.Message('Type: ' + Variables.GetVariableType(i));
    // Posts the variable’s default value to the test log
    Log.Message('Default Value: ' + aqConvert.VarToStr(Variables.GetVariableDefaultValue(i)));
    // Posts the variable’s description to the test log
    Log.Message('Description: ' + Variables.GetVariableDescription(i));

    Log.PopLogFolder;
    end;

end;

C++Script, C#Script

function Variables()
{

  var Variables, Count, VarName;

  // Obtains a list of project suite variables
  Variables = ProjectSuite["Variables"];
  // Obtains the total number of variables in the project suite
  Count = Variables["VariableCount"];

  // Iterates through the project suite variables
  for (var i = 0; i < Count; i++)
    {
    // Obtains a variable's name and posts it to the test log
    VarName = Variables["GetVariableName"](i);
    Log["AppendFolder"](VarName);

    // Posts the variable’s category to the test log
    Log["Message"]("Category: " + Variables.GetVariableCategory(i));
    // Posts the variable’s type to the test log
    Log["Message"]("Type: " + Variables.GetVariableType(i));
    // Posts the variable’s default value to the test log
    Log["Message"]("Default Value: " + Variables.GetVariableDefaultValue(i));
    // Posts the variable’s description to the test log
    Log["Message"]("Description: " + Variables.GetVariableDescription(i));

    Log["PopLogFolder"]();
    }

}

See Also

GetVariableCategory Method
GetVariableDescription Method
GetVariableType Method
VariableByName Property

Highlight search results