TheSwamp
Code Red => VB(A) => Topic started by: gromit on July 30, 2006, 05:21:53 PM
-
Hi there
In an app I have written I have a collection class. Between one sub and the following sub the collection goes from having members as it should to having none - which shouldn't happen! There is no code in between that does anything to the collection. The annoying thing is the app used to work then I made some changes and it doesn't. I can go back and compare the changed subs line by line as luckily do have an old version in zip file, but on initial perusal nothing that could make this happen has sprung out to me.
Any suggestions of possible causes of this behaviour, things to explore, would be much appreciated as right now this has me flummoxed.
Thanks
Jon
-
I'm not up with vba but is the collection static (shared)?
Also, if you are going from one sub to the other, perhaps your class is going out of scope and being destroyed??
-
... Between one sub and the following sub ...
Within the class or in an external module? If external is the class instance being passed from sub to sub, is it a member var (and possibly declared as a local in one of the subs), is it a global ...
Also, do you grant external access to the class anywhere, e.g. --
Public Function GetCol () as Collection
Set GetCol = myCollection
End Function
or
Public Property Get NewEnum() As IUnknown
Set NewEnum = myCollection.[_NewEnum]
End Property
etc.
Hard to do a post mortem without a body (post the code).
:)
-
I'm fairly certain it has to do with the scope of the variable that you are storing the collection class in. Pay close attention to exactly when that variable gets initialized and when it gets destroyed.
-
Of particular note, if you have a global variable defined for the collection class, and you declare a variable of the same name inside a sub or function, a second (local) variable is used for everything in that sub or function and is destroyed when the sub or function completes.
-
Thanks for the suggestions. Problem sorted - I had managed to declare the collection twice; one as a Public one in a normal module (which was what I wanted, so it was accessible to all the app and again as a private one in a class module - which was the offending line and once removed it all works as it should. Once again thanks for help.
Jon
-
Glad you got it sorted out, tho I had no doubt given your namesake, clever lil' fellow that Gromit is.
:)