GetVariableDefaultValue Method

Applies to TestComplete 14.92, last modified on September 16, 2021

Description

Use this method to obtain the default value of the variable specified by its name or index within the collection. This is the value shown in the Default Value column of the Variables page.

Declaration

VariablesObj.GetVariableDefaultValue(Variable)

VariablesObj An expression, variable or parameter that specifies a reference to a Variables object
Variable [in]    Required    Variant    
Result Variant

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Variable

Either the variable’s unique name or its index within the variables collection. The index is zero-based, so the first variable has the index 0, the second - 1 and so on.

Result Value

A variant value that specifies the variable’s default value. For variables of the Object type, this property always returns an empty value (Nothing in VBScript, null in JavaScript, JScript, C++Script and C#Script, None in Python and nil in DelphiScript).

Remarks

TestComplete does not pass the default value of network suite variables to remote projects in order to increase the network suite performance. In remote projects’ scripts, the NetworkSuite.Variables.GetVariableDefaultValue method returns the default value of the variable type. The default string value is an empty string, integer and double values - 0, boolean value - False.

If a variables collection does not contain the specified variable, an error occurs.

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

GetVariableDescription Method
GetVariableName Method
GetVariableType Method

Highlight search results