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

Introduction of Sub statement in VBS

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "introduction of Sub sentences in VBS". In daily operation, I believe many people have doubts about the introduction of Sub sentences in VBS. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "introduction to Sub sentences in VBS". Next, please follow the editor to study!

Declare the name of the Sub procedure, its parameters, and the code that forms its body.

[Public [Default] | Private] Sub name [(

Arglist

)]

[statements]

[Exit Sub]

[statements]

End Sub

Parameter Public

Indicates that the Sub procedure can be accessed by all other procedures in all scripts.

Default

Used only with the Public keyword in the class block to indicate that the Sub procedure is the default method of the class. If more than one Default procedure is specified in the class, an error will occur.

Private

Indicates that a Sub procedure can only be accessed by other procedures in the script that declares the procedure.

Name

The name of the Sub, following the standard variable naming convention.

Arglist

Represents a list of variables to pass to the Sub procedure on call. Separate multiple variables with commas.

Statements

Any group of statements executed within the body of the Sub procedure.

The arglist parameter contains the following syntax and sections:

[ByVal | ByRef] varname [()]

Parameter ByVal

Indicates that the parameter is passed by value.

ByRef

Indicates that the parameter is passed by reference.

Varname

The variable name that represents the parameter, following the standard variable naming convention.

Description

If you do not explicitly specify the use of Public or Private, Sub procedures are public by default, that is, they are visible to all other procedures in the script. The value of the local variable in the Sub procedure is not retained during the call.

Sub procedures cannot be defined in any other process (for example, Function or Property Get).

You can exit from the Sub procedure immediately by using the Exit Sub statement. The program continues to execute the statement after the statement that calls the Sub procedure. You can have any Exit Sub statement anywhere in the Sub process.

Similar to the Function procedure, the Sub procedure is an independent process that takes parameters, executes a series of statements, and changes the values of its parameters. Unlike the Function procedure, the Function procedure can return a value, while the Sub procedure cannot be used in an expression.

You can use the procedure name and follow the corresponding parameter list to call the Sub procedure. For more information about how to call the Sub procedure, see the Call statement.

Be careful that the Sub procedure can be recursive, that is, it can call itself to complete a given task. But recursion can cause stack overflows.

The variables used in Sub procedures fall into two categories: one is explicitly declared within the procedure, and the other is not. Variables explicitly declared within a procedure (using Dim or equivalent methods) are always local variables. Variables that are not explicitly declared in the procedure are also local unless they are explicitly declared at a higher level outside the procedure.

Careful procedures can use variables that are not explicitly declared within the procedure, but name conflicts occur as long as any script-level definition has the same name. If an undeclared variable referenced in a procedure has the same name as another procedure, constant, or variable, the procedure is considered to refer to a script-level name. To avoid such conflicts, use the Option Explicit statement to force explicit declaration of variables.

At this point, the study of "introduction to Sub sentences in VBS" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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