Custom actions created with script extensions can generate script code that uses variables. After creating a variable declaration, you can generate code that uses this variable. To generate an expression containing a variable name, follow these steps:
-
Call the
Syntax.CreateInvoke
method to create a newInvokeSyntax
object. -
Specify the variable name in the
InvokeName
property of the createdInvokeSyntax
object. -
Set the object’s
IsProperty
property to True.
The resulting InvokeSyntax
object can be used to create more complex expressions and statements, for example, assignment statements (see Generating Assignment Statements).
The following example demonstrates how to generate an expression that refers to the MyVar variable:
JScript
function ShowPropertyStatement()
{
var oVarName = Syntax.CreateInvoke();
oVarName.InvokeName = "MyVar";
oVarName.IsProperty = true;
var strCode = Syntax.GenerateSource(oVarName);
aqDlg.ShowMessage(strCode);
}
VBScript
Sub ShowPropertyStatement
Dim oVarName, strCode
Set oVarName = Syntax.CreateInvoke
oVarName.InvokeName = "MyVar"
oVarName.IsProperty = True
strCode = Syntax.GenerateSource(oVarName)
aqDlg.ShowMessage strCode
End Sub
See Also
Generating Script Code
Generating Variable Declarations
Generating Object Property Expressions
InvokeSyntax Object
Syntax.CreateInvoke Method