Unkown Cls/Collection Holding An Event (3 Viewers)

Thank you both so much for extremely detailed high quality help. As mentioned I did many iterations & playing around massively all day long trying to understand what was going on & just to get it to work. I want to understand classes & events amongst other things. The input I have received from you both here is invaluable so I am extremely grateful. I have a long way to go in learning still.

Double check that you do not have a mouse up event in the form itself...

You ran the code and it hung. Then you saved your form from design view and if I now look in your form this is in all the events
=handleRightClickOnBillAndPageF()
You're right as usual. No indication in the menu but debugging the controls individually the mouseUpEvent still assigned to the controls. But I do not understand as how the events stayed there. In the book they die with the termination of the cls.
Is the lesson here that when saving the form in design-view it saves any VBA assigned properties to the frm. I think the event's have stayed around because as you point out I did not assign them to the cls, but wrote them to the property of the form. I'm surprised Access does not display [Event Procedure] in the form's properties to indicate VBA alterations to the properties of said frm.

But unless there is more to it, there is no need for the class...
Thanks, yeah I'm finding it difficult to find where to use classes; desperately want to understand them as I think it's a level up.
You need a collection outside of the class to hold the instances. Now you are declaring a bunch of instances of your cls that has a property of a collection that only holds an instance of itself. Not only does that do nothing, but I guess it is a circular reference. You created a property in a class that references the class..
Thanks - a valuable lesson learned here. I was playing around creating collections all over the place trying to learn. I didn't grasp it but with your help I'm one step further to understanding.

The definition of a memory leak is that the objects are no longer accessible in code. The variables they were assigned to on creation no longer exist, but their references with each other are still valid, so garbage collection does not destroy them. You could only find them back from memory if you used the ObjPtr() function to save the actual memory address of the object before all your known variables go out of scope.

WithEvents object variable maintains a collection of references to its subscribers so it knows what handlers to call when the event fires. If you have multiple WithEvents variables that expose the same instance of an object--like some kind of global notification object--then you have to explicitly destroy your WithEvents variables too.

If I create circular references in code in a form, I handle the Form_Unload() event and destroy that structure explicitly...
Thanks, extremely interesting & valuable lesson learned. Thank you for explaining it so well. So presumably an unterminated WithEvents var costs more memory when leaked than another var. I have not read this anywhere else yet so big thanks.
Correct me if I'm wrong & not trying to justify myself here at all - are the memory leaks terminated at shut-down of the application?

you do not trap the event in the class. You would add it like this in your class.

Code:
Private Sub mObjTxtBox_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

End Sub

I hate to say it but looks like you took three separate examples and kind of mashed them together all incorrectly.
1. Using a function to handle multiple controls
2. Using a collection outside of the class to hold instances of the class
3. Using with events to trap a controls event in the class.
Thanks for your honest feedback. Your input has really helped me try to understand it. Don't forget the CommandBar, I made a mess of that too :eek:.
I think I get the point you're making. I assigned the event to the form property event itself:
Code:
Private WithEvents mObjTxtBox As TextBox

 mObjTxtBox.OnMouseUp = "=handleRightClickOnBillAndPageF()"
I was wondering why the format .OnMouseUp was giving me intellisence & I thinking why is this intellisence appearing like a property. This now makes sense why the Event is sticking around; I stupidly didn't even assign it to the cls.

the functionality you call at handleRightClickOnBillAndPageF() is encapsulated within the class. This promotes tidy code, because it reduces the pollution of your global namespace...
I would never have figured this out, thank you.

Beyond grateful to you both for the input & generosity in the time you've taken to explain & explain it so well. I have learnt so much from you both here that I simply wouldn't have been able to do on my own. It's embarrassing as I've been studying so hard I should've been able to grasp these concepts. Thanks again.

Two things that I am mystified to still though:
1 - There seems no User-Collection
2 - Ditto with user-classes
:eek::unsure:(n)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom