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

What is a VBScript process?

2025-01-19 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 "what is the VBScript process". In the operation of actual cases, many people will encounter such a dilemma. Then 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!

Process classification

In VBScript, processes are divided into two categories: Sub processes and Function processes.

Sub process

A Sub procedure is a set of VBScript statements contained between Sub and End Sub statements that perform actions but do not return values. Sub procedures can use parameters (constants, variables, or expressions passed by the calling procedure). If the Sub procedure has no parameters, the Sub statement must contain empty parentheses ().

The following Sub procedure uses two inherent (or built-in) VBScript functions, MsgBox and InputBox, to prompt the user for information. The results of the calculation based on this information are then displayed. The calculation is done by the Function process created using VBScript. This process is demonstrated after the following discussion.

Sub ConvertTemp ()

Temp = InputBox ("Please enter Fahrenheit temperature." , 1)

MsgBox "temperature is" & Celsius (temp) & "degrees Celsius."

End Sub

Function process

A Function procedure is a set of VBScript statements contained between Function and End Function statements. The Function procedure is similar to the Sub procedure, but the Function procedure can return a value. Function procedures can use parameters (constants, variables, or expressions passed by the calling procedure). If the Function procedure has no parameters, the Function statement must contain empty parentheses (). The Function procedure returns a value through the function name, which is assigned to the function name in the statement of the procedure. The data type of the Function return value is always Variant.

In the following example, the Celsius function converts Fahrenheit to degrees Celsius. When the Sub procedure ConvertTemp calls this function, the variable containing the parameter value is passed to the function. The conversion result is returned to the calling procedure and displayed in the message box.

Sub ConvertTemp ()

Temp = InputBox ("Please enter Fahrenheit temperature." , 1)

MsgBox "temperature is" & Celsius (temp) & "degrees Celsius."

End Sub

Function Celsius (fDegrees)

Celsius = (fDegrees-32) * 5 / 9

End Function

Data entry and exit of the process

The way to pass data to a process is to use parameters. Parameters are used as placeholders for the data to be passed to the procedure. The parameter name can be any valid variable name. When you create a procedure using Sub or Function statements, the procedure name must be followed by parentheses. All parameters are contained in parentheses, separated by commas. For example, in the following example, fDegrees is a placeholder for the value passed to the Celsius function:

Function Celsius (fDegrees)

Celsius = (fDegrees-32) * 5 / 9

End Function

To get data from a procedure, you must use a Function procedure. Remember, the Function procedure can return a value; the Sub procedure does not.

Using Sub and Function procedures in your code

When calling the Function procedure, the function name must be used at the right end of the variable assignment statement or in the expression. For example:

Temp = Celsius (fDegrees)

Or

MsgBox "temperature is" & Celsius (fDegrees) & "degrees Celsius."

When calling a Sub procedure, you only need to enter the procedure name and all parameter values, separated by commas. You do not need to use the Call statement, but if you do, you must include all parameters in parentheses.

The following example shows two ways to call a MyProc procedure. One uses the Call statement; the other does not. The two methods have the same effect.

Call MyProc (firstarg, secondarg)

MyProc firstarg, secondarg

Note that parentheses are omitted when the call is made without the Call statement.

This is the end of what is the VBScript process. Thank you for your 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