Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of Execute statement in VBS

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "the use of Execute sentences in VBS". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Executes one or more specified statements.

Execute statements

The required statements parameter is a string expression that contains one or more statements to be executed. If you want to include multiple statements in the statements parameter, you should separate them with semicolons or embedded branches.

Description

In VBScript, x = y can be interpreted in two ways. The first is to assign the value of y to x as an assignment statement. The second is as an expression to 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 interpretation, while the Eval method always uses the second.

Note that 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 called determines the objects and variables that can be used by the code to run. Objects and variables within scope can be used by code running in an Execute statement. It is important to understand, however, that if the executed code creates a procedure, the procedure will not inherit the scope of the procedure in which it is located.

Like other processes, the scope of the new process is global, and it inherits everything in the global scope. Unlike other procedures, its context is not in global scope, so it can only be executed in the context of the procedure in which the Execute statement occurs. However, if the same Execute statement is called outside the scope of the procedure (for example, in the global scope), it will not only inherit everything in the global scope, but it can also be called anywhere because its context is global. The following example illustrates this feature:

Dim X 'declares X in the global scope. X = "Global" 'assigns the global X value. Sub Proc1 'declaration process. Dim X 'declares X in the local scope. X = "Local" 'assigns a local X value. The Execute statement here establishes a procedure that prints an X when the procedure is called. 'it will print global X, because Proc2 'inherits everything in the global scope. Execute "Sub Proc2: Print X: End Sub" Print Eval ("X") 'prints the local X. Proc2 'calls Proc2 in the scope of Proc1. End SubProc2 'this line will cause an error because' Proc2 is not available outside of Proc1. Proc1 'calls Proc1. The phrase Execute "Sub Proc2: Print X: End Sub" Proc2 'can be successful because Proc2' is now available globally.

The following example shows how to rewrite an Execute statement without enclosing the entire procedure in quotation marks:

S = "Sub Proc2" & vbCrLfS = S & "Print X" & vbCrLfS = S & "End Sub" Execute S "usage of Execute sentences in VBS" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report