Using Public Variables

One way to create properties for a class is to use a public variable declaration in a class module. In Chapter 3, you learned how to write a public variable declaration. When you place a public variable declaration in the Declarations section of a class module, it becomes a property for that class. Here is an example:

Public VehicleIdNumber As Double

I do not recommend creating properties using public variables for several reasons. First, you cannot manipulate the value because the property is set. Second, you cannot create read-only and write-only properties. Third, you cannot easily validate what is assigned to public variables. The better way to create properties is discussed next and does not have these drawbacks.

0 0

Post a comment