What are the differences among Eval, Execute and ExecuteGlobal
This article mainly explains "what are the differences between Eval, Execute and ExecuteGlobal". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the differences between Eval, Execute and ExecuteGlobal?"
Syntax: [result=] eval_r (expression_r)
Expression_r is a string of any valid VBScript expression
Example:
The code is as follows:
Response.Write (eval_r ("3x2")) 'output 5
"3percent 2" is enclosed in quotation marks to indicate that it is a string, but in Eval's "eyes", it is executed as an expression 3percent 2.
Execute executes one or more specified statements. Multiple statements are separated by a colon (:).
Syntax: Executestatements
Example:
Execute "response.Write ("abc")" 'outputs abc
"response.Write ("abc")" is enclosed in quotation marks to indicate that it is a string
But in Execute's "eyes", it is executed as a statement response.Write ("abc").
ExecuteGlobal executes one or more specified statements in the global namespace.
Syntax: ExecuteGlobalstatement
What's the difference among Eval, Execute and ExecuteGlobal?
Example:
The code is as follows:
Dimc
C = "global variable"
SubS1 ()
Dimc
C = "local variable"
Execute "response.Write (c)" 'outputs local variables
ExecuteGlobal "response.Write (c)" 'outputs global variables
Endsub
Execute "response.Write (c)" 'outputs global variables
CallS1 ()
The variable c is defined in both the global scope and the function scope. Execute decides to use local variables or global variables according to its location, while ExecuteGlobal always recognizes only the global scope c.
Summary:
Eval executes only one statement statement with or without a return value
Execute executes one or more statements to ignore the return value of the statement
ExecuteGlobal always uses global variables when executing one or more statements ignoring the return value of the statement when global variables and local variables have the same name
Note:
In VBScript, both "assignment" and "comparison" use "=". For example, "aquib" can be said to assign a value to a, or to judge whether an is equal to b, so does eval_r ("aquib") mean assignment or comparison operation?
Here's a convention: in Eval, "axib" always means comparison, and in Execute and ExecuteGlobal, it always means assignment.
At this point, I believe you have a deeper understanding of "what is the difference between Eval, Execute and ExecuteGlobal". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!