Execute statement
Execute one or more specified statements.
Execute statements
RequiredStatementsA parameter is a string expression that contains one or more statements to be executed. If you wantStatementsThe parameter contains multiple statements, which should be separated by semicolons or embedded branches.
Description
In VBScript,X = yThere are two possible interpretations. First, as the value assignment statementYValueX. Second, as an expression, testXAndYIs the value equal. If they are equal,ResultIsTrue; Otherwise,ResultIsFalse.ExecuteThe statement always uses the first explanation, whileEvalThe second method is always used.
Note:There is no confusion between values assignment and comparison in Microsoft (R) Visual Basic Scripting Edition, because the value assignment operator (=) and comparison operator (=) are different.
CallExecuteThe context of the statement determines the objects and variables that can be used by the code to run. The objects and variables in the scope areExecuteThe code running in the statement can be used. However, you must understand that if the code to be executed is created, the process will not inherit the scope of the process.
Similar to other processes, the scope of the new process is global, and it inherits everything from the global scope. Unlike other processes, the context is not a global scope, so it can onlyExecuteStatement execution in the context. However, if the sameExecuteA statement is called outside the scope of a process (for example, in a global scope), so it not only inherits everything in the global scope, but also can be called anywhere, because its context is global. The following example illustrates this feature:
Dim X
'
Declare IN GLOBAL SCOPE X
.X = "Global"
'
X
Assign values.Sub Proc1
'
Declaration process. Dim X
'
Declare in local scope X
. X = "Local"
'
Partial X
Assign values.'
Here Execute
Statement creates a process,'
When this process is called, it will print X
.'
It prints global X
Because Proc2
'
Inherits everything in the global scope. Execute "Sub Proc2: Print X: End Sub"
Print Eval("X")
'
Print local X
. Proc2
'
In Proc1
Called in the scope Proc2
.End Sub
Proc2
'
This line will cause an error because' Proc2
In Proc1
Is not available.Proc1
'
Call Proc1
. Execute "Sub Proc2: Print X: End Sub"
Proc2
'
This statement can be successful, because Proc2
'
It is now globally available.
The following example shows howExecuteStatement rewriting to avoid including the entire process in quotation marks:
S = "Sub Proc2" & vbCrLfS = S & " Print X" & vbCrLf S = S & "End Sub"Execute S