J
joeu2004
How and where can I declare variables that are intended to be shared
by objects of a class?
For example, suppose I want each object of a class to have a unique
instance numbers. I have the following class module:
Private objInst As Long
Private Sub Class_Initialize()
objcnt = objcnt + 1
objInst = objcnt
End Sub
Property Get instNum() 'read-only
instNum = objInst
End Property
As written, objcnt must be a global or static variable somewhere that
is initially zero.
The only way I am able to do that is to declare Public objcnt in a
standard module. That violates the concepts of class encapsulation
and data hiding. It also exposes objcnt to corruption.
by objects of a class?
For example, suppose I want each object of a class to have a unique
instance numbers. I have the following class module:
Private objInst As Long
Private Sub Class_Initialize()
objcnt = objcnt + 1
objInst = objcnt
End Sub
Property Get instNum() 'read-only
instNum = objInst
End Property
As written, objcnt must be a global or static variable somewhere that
is initially zero.
The only way I am able to do that is to declare Public objcnt in a
standard module. That violates the concepts of class encapsulation
and data hiding. It also exposes objcnt to corruption.