Procedures are chunks of code that are called upon by name.

Procedure Scope

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. 

Procedure Arguments

[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.


Sub ProcedureName (M, _
                   N As String, _
                   ByVal O, _
                   P = 12, _
                   Optional Q, _
                   Optional ParamArray R())

Procedure Calls

When called, parameters are usually passed to the procedure in the same order as the arguments were listed at the procedure declaration.


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:

Sub Procedures

[Private|Public|Friend] [Static] Sub SubProcedureName ([Arguments])
End Sub

Sub Procedures can modify arguments passed to it but cannot return a value itself.

Sub Procedures come in one of two types:

  1. Event Procedures are actions in response to events, such as clicking on a control. Syntax:
[Private|Public|Friend] [Static] Sub Object_Event ([Arguments])
End Sub
  1. General Procedures are Sub Procedures which are not Event Procedures but must be explicitly evoked. Syntax:
[Private|Public|Friend] [Static] Sub SubProcedureName ([Arguments])
End Sub

Function Procedures

[Private|Public|Friend] [Static] Function FunctionName([Arguments])[ As Type]
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.


Property Procedures

Property Procedures are procedures basically used to set properties for a class of objects. See VB OOP.

Page Modified: (Hand noted: ) (Auto noted: )