VariableExists Method

Applies to TestComplete 15.10, last modified on December 01, 2021

Description

This method checks to see if a local variable exists in the collection designated by the given Variables object. The variable is specified by its name, which is unique in the collection.

Declaration

VariablesObj.VariableExists(Name)

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

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Name

Specifies the name of the local variable whose presence in the given collection you want to check.

Result Value

True if the local variable is part of the given variable collection and otherwise it is False.

Example

The following code snippet checks whether the specified variable exists in a variable collection.

JavaScript, JScript

function Test()
{

  var Variables, VarName;
  // …

  // Obtains a variable collection
  Variables = ProjectSuite.Variables;
  VarName = "MyVar";

  // Checks whether the MyVar variable exists in the project suite
  if (Variables.VariableExists(VarName))
    Log.Message("The " + VarName + " variable exists in the project suite.");
  else
    Log.Error("The " + VarName + " variable does not exist in the project suite.");

  …
}

Python

def Test():
  # ...
  # Obtains a variable collection
  Variables = ProjectSuite.Variables
  VarName = "MyVar"
  # Checks whether the MyVar variable exists in the project suite
  if Variables.VariableExists(VarName):
    Log.Message("The " + VarName + " variable exists in the project suite.")
  else:
    Log.Error("The " + VarName + " variable does not exist in the project suite.")
  # ...

VBScript

Sub Test

  Dim Variables, VarName
  ' …

  ' Obtains a variable collection
  Set Variables = ProjectSuite.Variables
  VarName = "MyVar"

  ' Checks whether the MyVar variable exists in the project suite
  If Variables.VariableExists(VarName) Then
    Log.Message("The " & VarName & " variable exists in the project suite.")
  Else
    Log.Error("The " & VarName & " variable does not exist in the project suite.")
  End If
  …
End Sub

DelphiScript

procedure Test();
var Variables, VarName;
begin

  // …

  // Obtains a variable collection
  Variables := ProjectSuite.Variables;
  VarName := 'MyVar';

  // Checks whether the MyVar variable exists in the project suite
  if Variables.VariableExists(VarName) then
    Log.Message('The ' + VarName + ' variable exists in the project suite.')
  else
    Log.Error('The ' + VarName + ' variable does not exist in the project suite.');

  …
end;

C++Script, C#Script

function Test()
{

  var Variables, VarName;
  // …

  // Obtains a variable collection
  Variables = ProjectSuite["Variables"];
  VarName = "MyVar";

  // Checks whether the MyVar variable exists in the project suite
  if (Variables["VariableExists"](VarName))
    Log["Message"]("The " + VarName + " variable exists in the project suite.");
  else
    Log["Error"]("The " + VarName + " variable does not exist in the project suite.");

  …
}

See Also

Variables.AddVariable
Variables.RemoveVariable
Variables.VariableByName

Highlight search results