VBScript Programs
- Previous Page VB Variables
- Next Page VB Conditional Statements
Example
- Subroutine
- This subroutine does not return a value.
- Function Program
- If you want to return a value, you can use a function program.
VBScript Programs
We can use two types of programs: subroutine and function program.
Subroutine:
- It is a series of statements enclosed within the Sub and End Sub statements.
- It can perform certain operations but will not return a value.
- It can have parameters passed to the subroutine through program calls.
- If not, it must have empty parentheses
Sub mysub() some statements End Sub
Sub mysub(argument1, argument2) some statements End Sub
Function Program:
- It is a series of statements encapsulated within the Function and End Function statements.
- It can perform certain operations and return a value.
- It can have parameters passed to it through program calls.
- If not, it must have empty parentheses
- By assigning a value to the function program name, it can return a value.
Function myfunction() some statements myfunction=some value End Function
Function myfunction(argument1,argument2) some statements myfunction=some value End Function
Calling Subroutines or Function Procedures
You can call a function in this way:
name = findname()
This function is named "findname", the function will return a value, which will be stored in the variable "name".
Or you can do it this way:
msgbox "Your name is " & findname()
We called a function named "findname", the value returned by this function will be displayed in the message box.
You can call the subroutine in this way:
Call MyProc(argument)
Or, you can also omit the Call statement:
MyProc argument
- Previous Page VB Variables
- Next Page VB Conditional Statements