|
|
|
|
||
Read-only properties<< Back to Classes index pageIntroductionIn our first simple example clsSimple, all the properties - OrderID and so forth - could be altered by a VBA program because they were declared as Public. If we want some of our properties to be read-only, we need to make the variable Private and use the Property Get statement. Instructions
Actually, this particular example isn't really much use, but we'll see in later lessons how this code can be used very effectively to protect important properties, such as the OrderID, from accidental changes. The opposite to the Property Get statement is the Property Let statement. If you look up the help on class modules you'll see examples like this:
Option Compare Database
Option Explicit
Private mlOrderID As Long
Property Get OrderID() As Long
OrderID = mlOrderID
End Property
Property Let OrderID(ID As Long)
mlOrderID = ID
End Property
In fact, this is no different to having a public variable OrderID like we did in our first simple example. This way just takes up more code. However, there are cleverer things to do with the Property Let statement, such as limiting the values it could take. A note on naming conventionsThe prefix cls used to name the Class Modules in the Modules window is another convention. You can call your classes anything you like, but it really helps if you are organised from the start. Having all your own Class Modules starting with cls differentiates them from the standard Access classes. The instances of objects defined in VBA code start with o (lower case letter O) as in oSim. Again, there are numerous conventions for this. It's a matter of personal preference. Feedback or questions: Contact DI Management. Return to Tips and Tutorials Page. |
|
|
| Copyright © 2000-5 DI Management Services Pty Limited ABN 78 083 210 584 Sydney, Australia. www.di-mgt.com.au. All rights reserved. | |
|
Home | What We Do | Services | Our Approach | About Us | Projects | Tips | Links | Cryptography | About This Site | Contact | Email Us |