VBS TUTORIAL: VBScript statement-execute statement _vbs

Source: Internet
Author: User
Tags eval

Execute statement

Executes one or more of the specified statements.

Execute statements

The required Statements parameter is a string expression that contains one or more statements to execute. If you want to include more than one statement in the statements parameter, you should separate it with a semicolon or an embedded branch.

Description

In VBScript,x = y can be interpreted in two ways. The first is to assign the value of y to xas an assignment statement. Second, as an expression, test whether the values of x and y are equal. If equal, the result is True, otherwise the result is False. The Execute statement always uses the first explanation, and the Eval method always uses the second.

Note There is no confusion between assignment and comparison in Microsoft (R) Visual Basic scripting Edition, because the assignment operator (=) is different from the comparison operator (= =).

The context in which the Execute statement is invoked determines the objects and variables that can be used by the code to be run. The objects and variables within the scope are available to code that is running in the Execute statement. However, it must be understood that if the code being executed creates a procedure, then the procedure will not inherit the scope of the procedure in which it resides.

Like other processes, the scope of the new process is global, and it inherits everything from the global scope. Unlike other procedures, its context is not a global scope, so it can only be executed within the context of the procedure in which the execute statement occurred. However, if the same Execute statement is invoked outside of the procedure, such as in the scope of the global scope, it will not only inherit everything in the global scope, but it can also be invoked anywhere, because its context is global. The following examples illustrate this feature:

Dim X' Declaring in the global scope XX = "Global"' to the global X Assigned value.Sub Proc1' The declaration process. Dim X' Declaring in a local scope X X = "Local"' to the Local X Assigned value.' Here's Execute Statement to create a procedure that' It will print when the procedure is called X' It will print the global XBecause 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 of the Proc2End SubProc2' The bank will cause an error because' Proc2 In Proc1 is not available outside of.Proc1 ' Call Proc1 Execute "Sub Proc2: Print X: End Sub"Proc2' This sentence can be successful, because Proc2' is now globally available.

The following example shows how to overwrite an Execute statement to avoid including the entire process in quotation marks:

S = "Sub Proc2" & vbCrLfS = S & "  Print X" & vbCrLf S = S & "End Sub"Execute S

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.