VBS Tutorial: VBscript statement-Execute statement

Source: Internet
Author: User

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 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 Proc2.End SubProc2            ' 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

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.