VBScript Programs
VBScript can use two types of programs:
- Subroutines
- Function programs
VBScript Subroutines
Subroutines:
- Are a series of statements encapsulated within Sub and End Sub statements
- Can perform certain operations but do not return a value
- Can have parameters
Or
Example (IE only)
VBScript Function Programs
Function programs:
- Are a series of statements encapsulated within Function and End Function statements
- Can perform certain operations and do return a value
- Can have parameters passed to them through program calls
- Must have empty parentheses () if there are no parameters
- Can return a value by assigning it to the function program name
Or
Example (IE only)
Calling Programs
This simple function program is called to calculate the sum of two parameters:
Example (IE only)
The function "myfunction" will return the sum of parameters "a" and "b". Here, it returns 14.
When you call a program, you can use the Call statement, as follows:
Or, you can omit the Call statement, as follows: