VariableByName Property

Applies to TestComplete 15.48, last modified on March 01, 2023

Description

This property returns a local variable from the collection designated by the given Variables object. The variable is specified by its name, which is unique in the collection.

Declaration

VariablesObj.VariableByName(Name)

Read-Write Property OleVariant
VariablesObj An expression, variable or parameter that specifies a reference to a Variables object
Name [in]    Required    String    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Name

Specifies the name of the local variable you want to obtain from the given variable collection.

Property Value

A local variable that is part of the given variable collection.

Remarks

If you use Python or DelphiScript, you should enclose the parameter of the VariableByName property in square brackets: VariableByName[Name].

Since the Variables collection holds properties whose names are the variable names, you can obtain the desired variable via its name instead of using the VariableByName property. The following constructions are equivalent:

JavaScript

VariablesObj.$set("VariableByName", variable_name, value);

VariablesObj.variable_name = value;

JScript

VariablesObj.VariableByName(variable_name) = value;

VariablesObj.variable_name = value;

Python

VariablesObj.VariableByName[variable_name] = value

VariablesObj.variable_name = value

VBScript

VariablesObj.VariableByName(variable_name) = value

VariablesObj.variable_name = value

DelphiScript

VariablesObj.VariableByName[variable_name] = value;

VariablesObj.variable_name = value;

C++Script, C#Script

VariablesObj["VariableByName"](variable_name) = value;

VariablesObj[variable_name] = value;

Example

The following code snippet obtains a variable by its name and assigns a new value to it:

JavaScript

function VariableByName()
{
  let Variables;

  // Obtains a variable
  Variables = ProjectSuite.Variables;
  // Sets a new value for the variable
  Variables.$set("VariableByName", "MyVar", "New value");

}

JScript

function VariableByName()
{
  var Variables;

  // Obtains a variable
  Variables = ProjectSuite.Variables;
  // Sets a new value for the variable
  Variables.VariableByName("MyVar") = "New value";

}

Python

def VariableByName():
  
  # Obtains a variable
  Variables = ProjectSuite.Variables
  # Sets a new value for the variable
  Variables.VariableByName["MyVar"] = "New value"

VBScript

Sub VariableByName
  Dim Variables

  ' Obtains a variable
  Set Variables = ProjectSuite.Variables
  ' Sets a new value for the variable
  Variables.VariableByName("MyVar") = "New value"

End Sub

DelphiScript

procedure VariableByName();
var Variables;

begin
  // Obtains a variable
  Variables := ProjectSuite.Variables;
  // Sets a new value for the variable
  Variables.VariableByName('MyVar') := 'New value';

end;

C++Script, C#Script

function VariableByName()
{
  var Variables;

  // Obtains a variable
  Variables = ProjectSuite["Variables"];
  // Sets a new value for the variable
  Variables["VariableByName"]("MyVar") = "New value";

}

See Also

Variables.GetVariableName
Variables.VariableExists

Highlight search results