VBScript Procedures | Rookie Tutorial
Rookie Tutorial -- Not only learning technology, but also dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Bookmarks
VBScript Tutorial
VB Tutorial VB Usage VB Variables VB Procedures VB Conditionals VB Loops VB Summary VB Examples VB Functions VB Keywords
Deep Dive
Programming
Web Browsers
Computer
Computer Hardware
Web Services
Web Design and Development
Computer Science
Software
Web Service
Computer
VBScript Procedures
VBScript can use two types of procedures:
- Sub procedures
- Function procedures
VBScript Sub Procedures
Sub procedures:
- Are a series of statements enclosed in Sub and End Sub statements
- Can perform certain actions but do not return a value
- Can take parameters
Sub mysub()
_some statements_
End Sub
Or
Sub mysub(argument1,argument2)
_some statements_
End Sub
Example (IE only)
Sub mysub()
document.write("I was written by a sub procedure")
End Sub
VBScript Function Procedures
Function procedures:
- Are a series of statements enclosed in Function and End Function statements
- Can perform certain actions and return a value
- Can take parameters passed to them through procedure calls
- Must have empty parentheses () if there are no parameters
- Return a value by assigning a value to the function procedure name
Function myfunction()
_some statements_
myfunction=_some value_
End Function
Or
Function myfunction(argument1,argument2)
_some statements_
myfunction=_some value_
End Function
Example (IE only)
function myfunction()
myfunction=Date()
end function
Calling Procedures
This simple function procedure is called to calculate the sum of two arguments:
Example (IE only)
Function myfunction(a,b)
myfunction=a+b
End Function
document.write(myfunction(5,9))
The function "myfunction" will return the sum of argument "a" and argument "b". Here it returns 14.
When you call a procedure, you can use the Call statement, as shown below:
Call MyProc(argument)
Or, you can omit the Call statement, as shown below:
MyProc argument
YouTip