Custom actions created with script extensions can generate code that compares two expressions or performs a logical operation over them. To generate such an expression, do the following:
-
Create syntax elements corresponding to the expressions to be placed on the left and right sides of the operator.
-
Create a
ConditionSyntaxobject using theSyntax.CreateConditionobject. -
Use the
OperatorTypeproperty of the createdConditionSyntaxobject to specify the comparison or logical operator to be used in the expression: >, <, >=, logical AND, and so on. -
Use the
LeftandRightproperties of theConditionSyntaxobject to specify the operands.Note: In the logical NOT operation, only the Rightoperand is required.
After you have configured the ConditionSyntax object, you can pass it to the Syntax.GenerateSource method to get the actual script code of the comparison or logical expression.
The following example demonstrates how to generate script code that checks whether the value of the variable x is greater than y.
JScript
function ShowConditionStatement()
{
var oXName = Syntax.CreateInvoke();
oXName.InvokeName = "x";
oXName.IsProperty = true;
var oYName = Syntax.CreateInvoke();
oYName.InvokeName = "y";
oYName.IsProperty = true;
var oCondition = Syntax.CreateCondition();
oCondition.OperatorType = oCondition.otGreater;
oCondition.Left = oXName;
oCondition.Right = oYName;
var strCode = Syntax.GenerateSource(oCondition);
aqDlg.ShowMessage(strCode);
}
VBScript
Sub ShowConditionStatement
Dim oXName, oYName, oCondition, strCode
Set oXName = Syntax.CreateInvoke
oXName.InvokeName = "x"
oXName.IsProperty = True
Set oYName = Syntax.CreateInvoke
oYName.InvokeName = "y"
oYName.IsProperty = True
Set oCondition = Syntax.CreateCondition
oCondition.OperatorType = oCondition.otGreater
oCondition.Left = oXName
oCondition.Right = oYName
strCode = Syntax.GenerateSource(oCondition)
aqDlg.ShowMessage strCode
End Sub
The generated code is as follows:
JavaScript, JScript
x > y
Python
x > y
VBScript
x > y
DelphiScript
x > y
C++Script, C#Script
x > y
See Also
Generating Script Code
Generating Conditional Statements
ConditionSyntax Object
Syntax.CreateCondition Method
