Forum Discussion
hlalumiere
11 years agoRegular Contributor
The sender parameter is a mostly universally accepted convention for event signatures. Most events will fire carrying a sender object, and usually also an eventarg object. In this particular case (OnStopTest) it might not be very useful, however it is usually used in cases when you need a reference to the specific instance of an object in memory. Sender is defined as an object, and to use it you would need to cast it to the proper type through late binding. For example:
Sub MyObject_SomeCoolEvent(sender, e)
Set instance = CreateObject("MyObjectClass")
Set instance = sender
...
End Sub
First you create an instance of the object class you know sender really is underneath that "object" hood to dimension and type the object, then you assign it your sender reference. Now you can access all of the intended members. In this case, you would have to figure out what type of object the event is referencing to be able to use its members beyond the base class (object) members.
Sub MyObject_SomeCoolEvent(sender, e)
Set instance = CreateObject("MyObjectClass")
Set instance = sender
...
End Sub
First you create an instance of the object class you know sender really is underneath that "object" hood to dimension and type the object, then you assign it your sender reference. Now you can access all of the intended members. In this case, you would have to figure out what type of object the event is referencing to be able to use its members beyond the base class (object) members.
Related Content
Recent Discussions
- 14 hours ago