Property Let
The Property Let statement allows you to declare
an accessor method for an object within a Class
definition. An accessor method allows the person who
creates an instance of the class to retrieve information
(properties) for the object without directly accessing the member variable itself.
You should use Property Let as opposed to Public
member variables wherever possible. This is just a good rule-of-thumb
when creating objects since it abstracts the data from the object.
If you decide later that you want to put tighter controls on the
member variable, you will be glad that you used a property because
you won't have to change the interface to the object.
When a Property Let statement is defined, the user of the object may set a value for that property. Conversely, the Property Get statement allows a user to read a value for the property. It is okay to use the same name for the Let, Get and Set properties.
Class Person ' demonstrates how you can control access to a private variable
Private m_nAge ' age of the person
Property Get Age() Age = m_nAge End Property
Property Let Age(nAge) If nAge >= 0 And nAge < 120 Then m_nAge = nAge End Property End Class
|
 |

|