Author Topic: Collection class empties for no apparent reason  (Read 2384 times)

0 Members and 1 Guest are viewing this topic.

gromit

  • Guest
Collection class empties for no apparent reason
« 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

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Collection class empties for no apparent reason
« Reply #1 on: July 30, 2006, 05:36:29 PM »
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??
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Collection class empties for no apparent reason
« Reply #2 on: July 30, 2006, 05:39:18 PM »
Quote
... 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. --

Code: [Select]
Public Function GetCol () as Collection

    Set GetCol = myCollection

End Function

or

Code: [Select]
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).

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

mmelone

  • Guest
Re: Collection class empties for no apparent reason
« Reply #3 on: July 31, 2006, 12:03:53 PM »
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.

mmelone

  • Guest
Re: Collection class empties for no apparent reason
« Reply #4 on: July 31, 2006, 12:06:43 PM »
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.

gromit

  • Guest
Re: Collection class empties for no apparent reason
« Reply #5 on: August 04, 2006, 03:55:39 PM »
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

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Collection class empties for no apparent reason
« Reply #6 on: August 05, 2006, 09:52:38 AM »
Glad you got it sorted out, tho I had no doubt given your namesake, clever lil' fellow that Gromit is.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst