RemoveVariable Method

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

Description

Use this method to remove the specified variable from the Variables collection.

Declaration

VariablesObj.RemoveVariable(VariableName)

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

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

VariableName

Specifies the name of the variable to be removed.

Result Value

None.

Remarks

If the variable with the specified name does not exist in the collection, an error occurs. To check if the variable exists, use the Variables.VariableExists method.

The RemoveVariable method cannot be used to delete network suite variables while the network suite is running. You can delete network suite variables in tests only before the network suite starts or after the network suite execution is finished. You can also delete network suite variables at design time.

Example

The following code snippet checks whether the MyVar variable exists in the collection of project variables and then removes it:

JavaScript, JScript

function RemoveVariable()
{
  var Variables, VarName;

  // Obtains a project variable
  Variables = Project.Variables;
  // Specifies the name of the variable
  VarName = "MyVar";

  // Checks whether the specified variable exists in the project
  if (Variables.VariableExists(VarName))
    {
    Log.Warning("The " + VarName + " variable will be removed from the project.");
    // If the specified variable exists, removes it
    Variables.RemoveVariable(VarName);
    }
  else
    Log.Warning("The " + VarName + " variables does not exist in the project.");

}

Python

def RemoveVariable():
  
  # Obtains a project variable
  Variables = Project.Variables
  # Specifies the name of the variable
  VarName = "MyVar"

  # Checks whether the specified variable exists in the project
  if (Variables.VariableExists(VarName)):
    Log.Warning("The " + VarName + " variable will be removed from the project.")
    # If the specified variable exists, removes it
    Variables.RemoveVariable(VarName)
  else:
    Log.Warning("The " + VarName + " variables does not exist in the project.")

VBScript

Sub RemoveVariable

  Dim Variables, VarName

  ' Obtains a project variable
  Set Variables = Project.Variables
  ' Specifies the name of the variable
  VarName = "MyVar"

  ' Checks whether the specified variable exists in the project
  If Variables.VariableExists(VarName) Then
    Log.Warning("The " & VarName & " variable will be removed from the project.")
    ' If the specified variable exists, removes it
    Variables.RemoveVariable(VarName)
  Else
    Log.Warning("The " & VarName & " variables does not exist in the project.")
  End If

End Sub

DelphiScript

procedure RemoveVariable();
var Variables, VarName;
begin
  // Obtains a project variable
  Variables := Project.Variables;
  // Specifies the name of the variable
  VarName := 'MyVar';

  // Checks wjether the specified variable exists in the project
  if (Variables.VariableExists(VarName)) then
    begin
    Log.Warning('The ' + VarName + ' variable will be removed from the project.');
    // If the specified variable exists, removes it
    Variables.RemoveVariable(VarName);
    end
  else
    Log.Warning('The ' + VarName + ' variables does not exist in the project.');

end;

C++Script, C#Script

function RemoveVariable()
{
  var Variables, VarName;

  // Obtains a project variable
  Variables = Project["Variables"];
  // Specifies the name of the variable
  VarName = "MyVar";

  // Checks whether the specified variable exists in the project
  if (Variables["VariableExists"](VarName))
    {
    Log["Warning"]("The " + VarName + " variable will be removed from the project.");
    // If the specified variable exists, removes it
    Variables["RemoveVariable"](VarName);
    }
  else
    Log["Warning"]("The " + VarName + " variables does not exist in the project.");

}

See Also

AddVariable Method
VariableExists Method

Highlight search results