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:
-
Create an
AssignSyntaxobject using theSyntax.CreateAssignmethod. -
Use the
LeftandRightproperties of the createdAssignSyntaxobject to specify the expressions to be placed on the corresponding sides of the assignment operator (=). For information on how to generate variable and object property expressions, see Generating Variable Expressions and Generating Object Property Expressions. -
If
Rightspecifies an expression that results in an object reference, set theIsObjectproperty to True. This is needed to generate a valid assignment statement in VBScript.
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:
JScript
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);
aqDlg.ShowMessage(strCode);
}
VBScript
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;
Python
MyVar = True
VBScript
MyVar = True
DelphiScript
MyVar := true;
C++Script, C#Script
MyVar = true;
See Also
Generating Script Code
Generating Variable Expressions
Generating Object Property Expressions
AssignSyntax Object
Syntax.CreateAssign Method
