How to catch events of objects in a collection in VBA?

Posted on 2012-09-18
Last Modified: 2012-09-18
I have defined an class - lets call it SomeClass - with a range of different events.
In order to create a functionality for storing and handling batches of these classes, I have also created a collection class - lets call it SomeClassCollection. Within this the SomeClass objects are stored in a collection.

I would really like to be able to catch the events of individual SomeClass objects in the collection. And let the SomeClassCollection object act accordingly (e.g. by raising its own event). Is this in any way possible?
Question by:andreas_rafn
    LVL 85

    Accepted Solution

    If you added a Parent property to the contained class, you could have the child class directly call a method of the parent class for its relevant events.

    Author Comment

    Not a bad idea, did not think of that myself. Regarding performance, I guess that adding a parent will not affect performance much as long as it is passed as a reference. How can I assure that? Is it as simple as adding the ByRef keyword to the set property, e.g.:

    Public Property Set Parent(ByRef ParentToSet as SomeObjectCollection)
       Set mParent = ParentToSet 
    End Property

    Open in new window

    LVL 85

    Expert Comment

    by:Rory Archibald
    If you pass an object ByVal you only pass a copy of the pointer, not a copy of the object, so I'm not sure how that would affect performance but using ByRef should work.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
    The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
    This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now