John W. Colby
jwcolby at colbyconsulting.com
Tue Sep 14 08:51:54 CDT 2004
Gustav, In fact I use something similar using withevents. As you know if a control is dimensioned Withevents, its events can be sunk in that class. What happens however when you have a class for each control, the number of controls monitored can vary, and yet you still want to be able to process each control in a loop and monitor the events for that control? By dimming a single control Withevents, you can now iterate the loop of control classes, get a pointer to the control that the class instance handles, and SET the single control variable to the control in the class. Now if the control (or the class if you are monitoring class events) fires an event, the supervisor can see it and process it. Since the supervisor knows which instance of the class or control it is processing at the moment it is easy to figure out what to do with the event. John W. Colby www.ColbyConsulting.com -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock Sent: Tuesday, September 14, 2004 4:15 AM To: Access Developers discussion and problem solving Subject: [AccessD] OT: Modify the default event handlers to mimic thebehavior of VB 6 control arrays (VB .NET) Hi all .Net freaks Just noticed this tip from Element K Journals. But is it just me or would this be considered bad programming practice? Whenever I find out an event for one control can be reused by another control, I move that code to a subfunction. /gustav --- If you've been mourning the loss of control arrays in VB .NET, wipe your eyes and listen up. While it's true that .NET put the control Index property out to pasture, you can still point multiple controls to an event subroutine just by modifying the event subroutines .NET exposes automatically when you add a control to a form. For example, suppose you have two buttons on a form named Button1 and Button2. You can make the Click() event subroutine for Button1 also handle the Click() event for Button2 just by adding Button2.Click to the Handles portion of the subroutine, like so: Private Sub Button1_Click(ByVal sender As _ Object, ByVal e As System.EventArgs) _ Handles Button1.Click, Button2.Click You can append as many control Click() events as you'd like to the Handles statement, as long as you separate each event with a comma. As an added bonus, you can also include other Button events or even events from any number of non-button control types on the form. That's more than you could ever do with a VB 6 control array. -- _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com