UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> Procedure    
Procedure

A Procedure is a code structure that exists in VBA modules and essentially performs some action. Procedures can be one of three forms:

  • Functions
  • Subs (Subprocedures)
  • Properties

Procedures are executed by calling them from other code or application expressions and run the code contained within until told to exit, thus returning the code process to the caller.

Functions

A Function is a procedure that returns a value.

CODE
Function MultiplyByTwo(InputValue As Double) As Double
 MultiplyByTwo = InputValue * 2
End Function

Functions are noteworthy in that they are visible to the Expression Service, unlike Subs. Functions are the most common type of procedure.

Subs

A Sub is a procedure that does not return a value.

CODE
Sub PrintValueToImmediate(InputValue As String)
 Debug.Print InputValue
End Sub

Properties

A Property is a two-part procedure that is typically used to provide an accessor to a value. These are helpful for data validation before setting values. The basic construct is as follows:

  • a Get property, used to return a value
  • a Let property, typically used to set the value of a standard value type
  • a Set property, typically used to set the value of an object, or reference type

Declaring Public or Private scope of a property signature is an effective means to control accessibility to the property.

A typical use case scenario for Properties is to expose a read-only value from a module.

CODE
Option Compare Database
Option Explicit

'a module-level variable to hold the value
Private mCount As Integer

'a public Get accessor so other modules can read the value
Public Property Get Count() As Integer
 Count = mCount
End Property

'a private Let accessor so only this module can set the value
'this is a good place to perform any input value validation
Private Property Let Count(i As Integer)
 mCount = i
End Property
Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 3,316 times.  This page was last modified 11:27, 5 June 2014 by Jack Leach.   Disclaimers