VBS Tutorial: VBscript statement-ExecuteGlobal statement

Source: Internet
Author: User

ExecuteGlobal statement

Execute multiple statements specified in the global namespace of the script.

ExecuteGlobal statement

StatementA parameter is a string expression that contains one or more executable statements. InStatementParameters can contain multiple statements and are separated by colons.

Description

In VBScript,X = yThere are two ways to explain. The first method is to assign a valueYAssignedX. The second method is used as an expression for testingXAndYWhether the same value exists. If they are equal, the result isTrue; If they are not equal, the result isFalse.ExecuteGlobalThe statement always uses the first method, whileEvalThe method always uses the second method.

Note:In Microsoft? Visual Basic Scripting Edition? There is no mixing between the value assignment and the comparison, because the value assignment operator (=) is different from the comparison operator.

In the global namespace of the script,ExecuteGlobalAll statements in are executable. Therefore, you can add code to a program so that any process can access it. For example, a VBScriptClassThe statement can be executed at runtime. Then the function creates a new instance of this type.

Adding processes and classes at runtime is very useful, but it may also overwrite existing global variables and functions at runtime. Because this may cause very serious program problems, when usingExecuteGlobalThe statement must be very cautious. If you do not need to access variables or functions outside of the process, it is best to useExecuteStatement, because it only affects the namespace of the main function.

The following example explainsExecuteGlobalStatement usage.

Dim X         ' Statement X Is a global variable.X = "Global"      ' To global variables X Assign values.Sub Proc1   ' Declaration process.  Dim X      ' Declare in local variables X.  X = "Local"   ' Give local variables X Assign values.' The executable statement here' Create a process, When called, Print X.' Global variables will be printed here X Because Proc2         ' Inherits everything from global variables.  ExecuteGlobal "Sub Proc2: Print X: End Sub"  Print Eval("X")   ' Print local X.  Proc2      ' Called in the Global Action Area Proc2          ' Print "Global" .End SubProc2         ' This row will cause errors          ' Because Proc2 In Proc1 Is not available.Proc1         ' Call Proc1.  Execute "Sub Proc2: Print X: End Sub"Proc2         ' This row is successfully called because Proc2         ' It is available in the global action area.

The following example demonstratesExecuteGlobalThe statement can be overwritten, so you do not need to include the following entire process in the reference tag.

S = "Sub Proc2" & vbCrLfS = S & "  Print X" & vbCrLf S = S & "End Sub"ExecuteGlobal 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.