0% found this document useful (0 votes)
28 views1 page

Sub Procedures

1. A sub procedure is a series of VBScript statements that performs actions but does not return a value. It can take arguments and use built-in functions like MsgBox and InputBox to prompt users for input. 2. The example sub procedure ConvertTemp prompts the user to enter a temperature in degrees Fahrenheit and displays the Celsius conversion using a function procedure. 3. A function procedure is similar to a sub procedure but can return a value. It takes arguments, performs calculations, and returns the result to the calling procedure to be used or displayed. The example Celsius function calculates and returns the Celsius equivalent of the degrees Fahrenheit passed to it.

Uploaded by

ahsivirah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views1 page

Sub Procedures

1. A sub procedure is a series of VBScript statements that performs actions but does not return a value. It can take arguments and use built-in functions like MsgBox and InputBox to prompt users for input. 2. The example sub procedure ConvertTemp prompts the user to enter a temperature in degrees Fahrenheit and displays the Celsius conversion using a function procedure. 3. A function procedure is similar to a sub procedure but can return a value. It takes arguments, performs calculations, and returns the result to the calling procedure to be used or displayed. The example Celsius function calculates and returns the Celsius equivalent of the degrees Fahrenheit passed to it.

Uploaded by

ahsivirah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Sub Procedures A Sub procedure is a series of VBScript statements, enclosed by Sub and End Sub statements, that perform

actions but don't return a value. A Sub procedure can take arguments (constants, variables, or expressions that are passed by a calling procedure). If a Sub procedure has no arguments, its Sub statement must include an empty set of parentheses (). The following Sub procedure uses two intrinsic, or built-in, VBScript functions, MsgBox and InputBox, to prompt a user for some information. It then displays the results of a calculation based on that information. The calculation is performed in a Function procedure created using VBScript. The Function procedure is shown after the following discussion.

Sub ConvertTemp() temp = InputBox("Please enter the temperature in degrees F.", 1) MsgBox "The temperature is " & Celsius(temp) & " degrees C." End Sub
Function Procedures A Function procedure is a series of VBScript statements enclosed by the Function and End Function statements. A Function procedure is similar to a Sub procedure, but can also return a value. A Function procedure can take arguments (constants, variables, or expressions that are passed to it by a calling procedure). If a Function procedure has no arguments, its Function statement must include an empty set of parentheses. A Function returns a value by assigning a value to its name in one or more statements of the procedure. The return type of a Function is always a Variant. In the following example, the Celsius function calculates degrees Celsius from degrees Fahrenheit. When the function is called from the ConvertTemp Sub procedure, a variable containing the argument value is passed to the function. The result of the calculation is returned to the calling procedure and displayed in a message box.

Sub ConvertTemp() temp = InputBox("Please enter the temperature in degrees F.", 1) MsgBox "The temperature is " & Celsius(temp) & " degrees C." End Sub Function Celsius(fDegrees) Celsius = (fDegrees - 32) * 5 / 9 End Function

You might also like