-
Sep 7th, 2020, 10:05 AM
#1
How does WithEvents get applied when declaring multiple objects on a single line
I'm writing some C# code that needs to parse some VBA code and identify any objects that have been declared WithEvents. I'm considering what would happen if multiple objects were declared on a single line.
Given the following VBA:-
VBA Code:
Dim WithEvents rv1 As AquatorModel.Reservoir, rv2 As AquatorModel.Reservoir
... would the WithEvents be applied to rv2 or only to rv1?
Thanks in advance
FD
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Sep 7th, 2020, 07:50 PM
#2
Re: How does WithEvents get applied when declaring multiple objects on a single line
It certainly is applied to both in VB.NET, so I would expect that it is the same in VBA, although that is not guaranteed.
Do you have a VBA editor available to you? If so, you can check for yourself by writing that code and then checking the navigation bar at the top of the code window. If both variables are included in the Object List then WithEvents applies to both of them. If only the first is listed then WithEvents would apply to only the first. You could also try applying WithEvents to the second and see if it's allowed, which it is not in VB.NET.
-
Sep 7th, 2020, 08:19 PM
#3
Re: How does WithEvents get applied when declaring multiple objects on a single line
Just tested on an older version of Microsoft Office.
Code:
Dim WithEvents A As ThingWithEvents, B As ThingWithEvents
results in only A showing up in the objects dropdown above the code window.
Code:
Dim WithEvents A As ThingWithEvents, WithEvents B As ThingWithEvents
results in both A and B showing up in the objects dropdown above the code window.
It is entirely possible that newer versions of Office handle this differently, but I can only test on what I have.
-
Sep 8th, 2020, 02:15 AM
#4
Re: How does WithEvents get applied when declaring multiple objects on a single line
Great, thanks to you both for that.
Do you have a VBA editor available to you?
Yes but what I don't have any more is the expertise to remember how to use it You're instructions should be enough to let me test it myself.
It's weird. I haven't touched VBA (or VB6 or VB.Net come to think of it) for years so I feel like I'm coding blind here
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|