Creating Simple Properties with VariablesThis 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.
A property sets and stores a characteristic of an object. The simplest way to create a property for a custom object is to add a public module-level variable to the class module. This variable behaves as a property of the object — you can set its value, and then retrieve the value later. A module-level variable in a class module exists as long as an instance of the class exists in memory, so you can count on the property being available for the lifetime of the object.
For example, the following line of code is all that you must create a property named FirstName within a hypothetical class named Customer:
Public FirstName As String
To set this property, create a new instance of the Customer class and provide a value for the property, as shown in the following code fragment:
Dim cstCust As New Customer cstCust.FirstName = "Maria"
The property that you create in this manner is always read-write, and there's no way to run other code when you set or return the property's value. Although this is an easy way to create a property when you are first beginning to program with class modules, you'll often find that you want to run code when a property is set or retrieved, or that you must make certain properties read-only.
Creating Scalar Properties | Why Build Your Own Objects? | Basic Class Concepts | Creating Property Procedures | Creating Events and Event Procedures | Extending Objects Through Interfaces | Designing Object Models | Creating Custom Objects for Web Pages