Private vs Public Class Modules
So does this mean that you are sorted now?
--
__________________________________
HTH
Bob
"Ronald R. Dodge, Jr." wrote in message
...
Okay, this is odd. The last time when I attempted to do just that within
a standard module, it gave me that same basic error message about me not
being able to assign a private class to a public variable. I do it again
this time around and it doesn't error out as I had expected based on
previous experience.
--
Thanks,
Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Bob Phillips" wrote in message
...
"Ronald R. Dodge, Jr." wrote in message
...
As far as declaring variables within class modules as public variables,
that's making implicit statements and not really good programming
practices. I rather use Property statements to expose such things than
to use the Public keyword within variable declarations. The only place
where I use public declarations like that are within standard modules,
which I have attempted to do but still get the same basic issue as I get
when attempting to turn the collection class as a public instance.
Whilst I did not suggest this, there is nothing wrong with it. A public
variable in a class module is a property, it is just an implicit
read/write property.
What I said is to declare the collection class variable as public, that
is the variable in the usage code that links to your collection class.
Somewhere in a standard module I assume you have some code similar in
logic to this pseudo code
Public MyCollClass As CollClass
Public Sub Do Stuff()
Dim MyBasicClass As BasicClass
Set MyCollClass = New CollClass
Set MyBasicClass = New BasicClass
With MyBasicClass
.'populate class instance #1
MyCollClass .Add MyBasicClass
End With
Set MyBasicClass = Nothing
Set MyBasicClass = New BasicClass
With MyBasicClass
.'populate class instance #2
MyCollClass .Add MyBasicClass
End With
Set MyBasicClass = Nothing
Set MyBasicClass = New BasicClass
With MyBasicClass
.'populate class instance #3
MyCollClass .Add MyBasicClass
End With
Set MyBasicClass = Nothing
End Sub
Then you can access each instance through the collection class
This sort of declaration is more or less like the same things as using
the "New" keyword within variable declarations rather than using it
within the procedures when creating new objects. You may think I'm
being harsh about sticking to good programming practices, but I have ran
into too many problems in the past and will only stick to these good
programming practices to avoid many of such issues down the road.
Not at all, I just have no idea how you are doing it. I have outlined
above how I do it.
The other thing, I would rather have the class seen by the entire
project than the collection data type variable itself. Reason being,
the class itself has a few things that the collection data type variable
doesn't have. Not only that, but there's greater control over the
variables within the class when it's handled properly within the class.
When variables starts getting handled outside of the class, too many
issues are of concern and I don't care for the risks involved with doing
that. Memory leaks is one such issue like that.
This I really don't understand. You expose the class through a variable.
You have to provide some means of referencing the class.
I use this technique regularly, and am not aware of any such problems.
|