VBScript Reference Manual for InduSoft Web Studio
VBScript Reference Manual for InduSoft Web Studio
VBScript Reference Manual for InduSoft Web Studio
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>InduSoft</strong> <strong>Web</strong> <strong>Studio</strong> <strong>VBScript</strong> <strong>Reference</strong> <strong>Manual</strong><br />
Execute<br />
Description Executes one or more specified statements in the local namespace.<br />
Usage Execute statement<br />
Arguments The required statement argument is a string expression containing one or more statements <strong>for</strong><br />
execution. Include multiple statements in the statement argument, using colons or embedded line<br />
breaks to separate them.<br />
Remarks In <strong>VBScript</strong>, x = y can be interpreted two ways. The first is as an assignment statement, where<br />
the value of y is assigned to x. The second interpretation is as an expression that tests if x and y<br />
have the same value. If they do, result is True; if they are not, result is False. The Execute<br />
statement always uses the first interpretation, whereas the Eval method always uses the second.<br />
The context in which the Execute statement is invoked determines what objects and variables<br />
are available to the code being run. In-scope objects and variables are available to code running<br />
in an Execute statement. However, it is important to understand that if you execute code that<br />
creates a procedure, that procedure does not inherit the scope of the procedure in which it<br />
occurred.<br />
Like any procedure, the new procedure's scope is global, and it inherits everything in the global<br />
scope. Unlike any other procedure, its context is not global scope, so it can only be executed in<br />
the context of the procedure where the Execute statement occurred. However, if the same<br />
Execute statement is invoked outside of a procedure (i.e., in global scope), not only does it<br />
inherit everything in global scope, but it can also be called from anywhere, since its context is<br />
global. The following example illustrates this behavior:<br />
Example Sub Proc1 'Declare procedure.<br />
Dim X 'Declare X in local scope.<br />
X = "Local" 'Assign local X a value.<br />
Execute "Sub Proc2: MsgBox X: End Sub" ‘Create a subroutine. Proc2 is local in scope<br />
MsgBox Eval("X") 'Print local X.<br />
Proc2 'Invoke Proc2 in Proc1's scope.<br />
End Sub<br />
Rem Main Program<br />
Dim X, s 'Declare X in global scope.<br />
X = "Global" 'Assign global X a value.<br />
Proc2 ‘Error - Proc2 is unavailable outside Proc1.<br />
Proc1 'Invokes Proc1.<br />
s = “ Main Program”<br />
Execute (“X = X & s”) ‘Concatenates strings<br />
Execute "Sub Proc2: MsgBox X: End Sub"<br />
Proc2 'Succeeds as Proc2 is now available globally.<br />
The result when executing the above code is:<br />
Local From MsgBox Eval(“X”) in Proc1<br />
Global From Proc2 statement in Proc1<br />
Global Main Program From Proc2 statement in Main program<br />
The following example shows how the Execute statement can be rewritten so you don't have to<br />
enclose the entire procedure in the quotation marks:<br />
S = "Sub Proc2" & vbCrLf<br />
S = S & " Print X" & vbCrLf<br />
S = S & "End Sub"<br />
Execute S<br />
<strong>InduSoft</strong>, Ltd. 177