Creating Property Procedures

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Public module-level variables in a class module function as properties of an object. However, they're not very sophisticated. If you must run code to set or return a property's value, or you want to make a property read-only, you can create a Property procedure. There are three types of Property procedures: Property Get, Property Let, and Property Set procedures. The Property Get procedure returns the current value of a property, whereas the Property Let procedure sets the value. The Property Set procedure assigns an object to an object property.

To create a read-write property, you must include a pair of Property procedures in the class module. Both procedures must have the same name. If the property stores and returns a scalar value, such as a numeric, text, or date value, you use a Property Let procedure to set the value and a Property Get procedure to retrieve it. If the property stores and returns a reference to an object, you use the Property Set procedure to store the reference and the Property Get procedure to return it.

In addition, you can create read-only, write-only, and write-once properties. The following table outlines which property procedures you must have for each type.

Type of property Procedures needed
Read-write, scalar Property Let, Property Get
Read-write, object Property Set, Property Get
Read-only, scalar Property Get
Read-only, object Property Get
Write-only, scalar Property Let
Write-once, scalar Property Let, including code to determine whether property has been set previously, Property Get
Write-once, object Property Set, including code to determine whether object property has been set previously, Property Get

See Also

Why Build Your Own Objects? | Creating Scalar Properties | Creating Object Properties | Basic Class Concepts | Creating Events and Event Procedures | Extending Objects Through Interfaces | Designing Object Models | Creating Custom Objects for Web Pages