We have two kinds of procedures: The Sub procedure and the Function procedure.
Sub procedure
A sub procedure is a series of statements, enclosed by the Sub and End Sub statements. It
can perform actions, but does not return a value. It can take arguments that are passed to it by a calling procedure. Sub procedures without arguments, must include an empty set of parentheses ()
Example:
Sub mysub()
some statement(s)
End Sub
Example:
Sub mysub(arg1,arg2)
Statement(s)
End Sub
Function procedure
A function procedure is a series of statements, enclosed by the Function and End Function statements. It can perform actions and can return a value. Function procedures can take arguments that are passed to it by a calling procedure. Without arguments, must include an empty set of parentheses (). They returns a value by assigning a value to its name.
Example
Function myfunction()
statement(s)
myfunction=some value
End Function
Example
Function myfunction(arg1,arg2)
Statement(s)
myfunction=some value
End Function
Calling a Sub or Function Procedure
Function name is used to call a function procedure. When you call a Function in your code, you do like this
Var_name = proc_name()
Here you call a Function called " proc_name", the Function returns a value that will be stored in the variable " Var_name".
Calling a sub procedure you can use the following statement.
Call Proc_name(arguments)
Or, you can omit the Call statement
Proc_name arguments