• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 130
  • Last Modified:

Monitor controls on a form

Is there a way to monitor all controls, e.x. combobox, textbox, and checkbox for events. I have a form with several of these controls that i want code generic events without having to monitor each controls events. Example: have have about 30 text boxes on this form and want to execute code based on the textbox change event. without have to repeat this 30 times for each control.
0
rawhide
Asked:
rawhide
  • 3
  • 3
  • 3
  • +2
1 Solution
 
tureCommented:
Putting the textboxes in a control array will allow for one single event procedure for all the textboxes.

Ture Magnusson
Karlstad, Sweden
0
 
jjmartinCommented:
Use a control array, then you only have to code things one time, and the change event would occur for each object in the array. This would probably be the prefered way.

If for some reason you cannot use an array, you could also use a public function or sub routine that each control calls when the change event happens, but you would still have to place code in the change event for each control, but the calling code could be more generic.
0
 
mark2150Commented:
This is why you should use control arrays. Instead of having 30 separate text boxes with 30 events you can have a control array of 30 text boxes and only *one* event that gets an *index* telling it which specific control was selected.

Each element in the control array can still be individually set, but they all share common event handlers.

This can reduce your memory footprint as well.

M

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
rawhideAuthor Commented:
I have these setup as arrays. let me put this another way.
I have an array of textboxes, checkboxes, and comboboxes. i want beable to set a save button to be enabled if any of the values change in any of the controls.
0
 
tureCommented:
rawhide,


If your array of textboxes is called Text1, then this should work:

Private Sub Text1_Change(Index As Integer)
  Command1.Enabled = True
End Sub

Ture Magnusson
Karlstad, Sweden
0
 
tureCommented:
..of course, you need to make a similar procedure for the checks and combos too.

/Ture
0
 
jjmartinCommented:
If a control array is not viable, you could also create your own user control that has the commen event procedure coded into it.  This is more complex, but it would place all the event code in a single place.
0
 
rawhideAuthor Commented:
This is not at all what i had in mind. I will figure something out. Just thought some might have tried this.
0
 
jjmartinCommented:
What exactly did you have in mind?  If you are looking for some global event or API that fires every time an event occurs in a given control type, it doesn't exist.
0
 
rawhideAuthor Commented:
Exactly What i was looking for. Maybe i'll just have to create one. didn't want to re-invent it if some one else has already accomplished it. thanks
0
 
gajendraCommented:
rawhide

I am certain VB does not (inherently) provide for what you are asking? What I am recommending below would be helpful only if you often write end-up rewriting such code.

I would recommend you design a activex control where you can set the change event of all the controls to trigger a common event - which you may handle externally.

It should not be difficult to code the activex to load textboxes and checkboxes etc. depending on txtboxcount, chkboxcount properties.

HTH

gajendra
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now