Executeglobal statement
Executes a function multiple statements specified in the script global namespace.
ExecuteGlobal statement
The statement parameter is a string expression that contains one or more executable statements. You can include more than one statement in the statement parameter, separating it with a colon.
Description
In VBScript, x = y can be interpreted in two ways. The first method is to assign a value of y to xas an assignment statement. The second method is an expression that tests whether x and y have the same value. If they are equal, the result is True; If they are not equal, the result is False. The executeglobal statement always uses the first method, and the Eval method always uses the second method.
Note at Microsoft? In Visual Basic scripting Edition, there is no blending between assignment and comparison because the assignment operator (=) differs from the comparison operator.
In the global namespace of the script, all the statements inExecuteglobal are executable. Therefore, you are allowed to add code to your program so that any process can access it. For example, a VBScript Class statement can be executed at run time. A new instance of this class is created with the function.
Adding procedures and classes at run time is useful, but it can also result in overwriting existing global variables and functions at run time. Because this can cause very serious procedural problems, you must be very cautious when using the executeglobal statement. If you do not need to access a variable or function other than the procedure, it is best to use the Execute statement, because it affects only the namespace of the keynote function.
The following example explains the use of the Executeglobal statement.
Dim X '
Statement X
As a global variable.X = "Global" '
To global variables X
Assigned value.Sub Proc1 '
The declaration process. Dim X '
Declaring in local variables X
。 X = "Local" '
to local variables X
Assigned value.'
The executable statement here'
Create a procedure,
When it is invoked,
Print X
。'
Global variables will be printed here X
The value, because Proc2
'
Inherits everything in the global variable. ExecuteGlobal "Sub Proc2:
Print X: End Sub"
Print Eval("X") '
Print Local X
。 Proc2 '
Called in the Global Action area Proc2
'
Will print "Global"
。End Sub
Proc2 '
This row will cause an error
'
Because Proc2
In Proc1
is not available.Proc1 '
Call Proc1
。 Execute "Sub Proc2:
Print X: End Sub"
Proc2 '
The row call succeeded because Proc2
'
is available in the Global Action area.
The following example shows that the Executeglobal statement can be overridden so you do not have to include the entire procedure below within the reference tag.
S = "Sub Proc2" & vbCrLfS = S & " Print X" & vbCrLf S = S & "End Sub"ExecuteGlobal S