Differences between ASP Eval, Execute, and ExecuteGlobal

Source: Internet
Author: User

Eval calculates the value of an expression and returns the result.
Syntax: [result =] eval_r (expression_r)
Expression_r is a string of any valid VBScript expression.
Example: Copy codeCode: response. Write (eval_r ("3 + 2") 'output 5

"3 + 2" is enclosed in quotation marks, indicating that it is a string, but in the Eval "eyes", it is executed as an expression 3 + 2.
Execute to Execute one or more specified statements. Multiple statements are separated by colons.
Syntax: Execute statements
Example:
Execute "response. Write (" abc "") "'output abc
Copy code
"Response. Write (" abc "") "is enclosed in quotation marks, indicating a string.
But in the eyes of Execute, it is executed as a statement response. Write ("abc.
ExecuteGlobal executes one or more specified statements in the global namespace.
Syntax: ExecuteGlobal statement
Example:Copy codeThe Code is as follows: dim c
C = "global variables"
Sub S1 ()
Dim c
C = "local variables"
Execute "response. Write (c)" 'output local variables
ExecuteGlobal "response. Write (c)" 'output global variables
End sub
Execute "response. Write (c)" 'output global variables
Call S1 ()

Variable c is defined both globally and within the function range. Execute determines whether to use local variables or global variables based on its location, executeGlobal always recognizes only the c in the global range.
Summary:
Eval can execute only one statement or return no value.
Execute runs one or more statements to ignore the return value of the statement.
ExecuteGlobal executes one or more statements to ignore the return value of the statement. When the global variable and the local variable have the same name, the global variable is always used.
Note:
In VBScript, "value assignment" and "comparison" both use "=". For example, "a = B" can be used to assign the value of B to, it can also be said to judge whether a and B are equal, so does eval_r ("a = B") indicate a value assignment or a comparison operation?
In Eval, "a = B" always indicates a comparison operation. In Execute and ExecuteGlobal, it always indicates a value assignment.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.