Procedures are chunks of code that are called upon by name.
There are three scopes that can be declared for procedures:
The Static keyword can be used when when declaring a procedure. It make the procedure remember the value of its local variables between calls. This is pretty stupid, because you might as well use a module or public level variable instead.
[Optional] [ByVal | ByRef] [ParamArray] VarName[( )] [As type] [= DefaultValue]
The arguments/parameters that a procedure can receive are set by listing them when the procedure is declared.
As keyword can be used to set the data type or object type.ByRef, i.e. the argument is tied to the address of the variable passed and changes to the argument occur to the original variable. The ByVal keyword can be used so just the value of a variable can be passed to the procedure and changes to the argument do not occur to the original variable.Optional keyword. Once the Optional keyword is used, all the arguments that follow must also be optional.ParamArray keyword can be used to accept arguments as an array of indeterminate length.EG:
Sub ProcedureName (M, _
N As String, _
ByVal O, _
P = 12, _
Optional Q, _
Optional ParamArray R())
When called, parameters are usually passed to the procedure in the same order as the arguments were listed at the procedure declaration.
EG:
ProcedureName myVariable, True, "Hello world!", 13
Call ProcedureName (M:=myVariable, O:="Hello world!", N:=True, P:=13)
There are two ways arguments are passed to procedures:
[Private|Public|Friend] [Static] Sub SubProcedureName ([Arguments]) [Statements] End Sub
Sub Procedures can modify arguments passed to it but cannot return a value itself.
Call SubProcedureName ([Arguments]) SubProcedureName [Arguments]
Sub Procedures come in one of two types:
[Private|Public|Friend] [Static] Sub Object_Event ([Arguments]) [Statements] End Sub
[Private|Public|Friend] [Static] Sub SubProcedureName ([Arguments]) [Statements] End Sub
[Private|Public|Friend] [Static] Function FunctionName([Arguments])[ As Type] [Statements] End Function
Function Procedures can modify arguments passed to it and can return values.
A Function Procedure is called just like a Sub Procedure, but it can also be called by using its name in an expression.
[FirstPartOfExpression1]FunctionName([Arguments])[SecondPartOfExpression]
Property Procedures are procedures basically used to set properties for a class of objects. See VB OOP.
2007-09-20 20:14:08Z