Generating Assignment Statements

Applies to TestComplete 15.42, last modified on August 01, 2022

Custom actions created with script extensions can generate code that assigns values to variables or object properties. To generate an assignment statement, do the following:

After you have configured the AssignSyntax object, you can pass it to the Syntax.GenerateSource method to get the actual script code of the assingment statement.

The following example demonstrates how you can generate code that assigns the value True to the MyVar variable:


function ShowAssignmentStatement ()
  var oVarName = Syntax.CreateInvoke();
  oVarName.InvokeName = "MyVar";
  oVarName.IsProperty = true;

  var oAssignment = Syntax.CreateAssign();
  oAssignment.Left = oVarName;
  oAssignment.Right = true;

  var strCode = Syntax.GenerateSource(oAssignment);


Sub ShowAssignmentStatement
  Dim oVarName, oAssignment, strCode

  Set oVarName = Syntax.CreateInvoke
  oVarName.InvokeName = "MyVar"
  oVarName.IsProperty = True

  Set oAssignment = Syntax.CreateAssign
  oAssignment.Left = oVarName
  oAssignment.Right = True

  strCode = Syntax.GenerateSource(oAssignment)
  aqDlg.ShowMessage strCode
End Sub

The generated code is as follows:

JavaScript, JScript

MyVar = true;


MyVar = True


MyVar = True


MyVar := true;

C++Script, C#Script

MyVar = true;

See Also

Generating Script Code
Generating Variable Expressions
Generating Object Property Expressions
AssignSyntax Object
CreateAssign Method

Highlight search results