Public Variables

Public variables declare the properties for the object.
When your properties are defined Public they are automatically available as properties of the class.
Any variables declared inside a class (even those declared as public) are not available outside of the class.
This is particularly relevant to Worksheet and Userform class modules.

Public property_sName As String 
Public property_dbHourlyRate As Double

Both these variables are declared as Public and therefore automatically become properties of this class.


Disadvantages of Public Variables

Class has no way of knowing if an outside process has changed the value.
There is no way of performing any data validation.
There is no way of creating read-only or write-only properties.


Alternative to Public Variables

The alternative is to use fields with property procedures instead.
Property Get - used to retrieve a property of a class. Get the value of scalar of object property.
Property Let - used to assign the value to a property of a class. Set the value of scalar property.
Property Set - used to assign an object to a property of a class. Set a reference for object property.


© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext