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

How to link an event procedure of many objects to one procedure in vb6

I have many comboboxes that need to listen for the GotFocus event.  In that event procedure the same code will be executed for each combobox.  I am trying to avoid having to code the same event for every combobox.  Is there a way to register all the comboboxes on a form with one event procedure without creating a control array?
  • 2
2 Solutions
You can call a common function from each ComboBox_GotFocus event, passing in a reference to which combo has the focus:

Private Sub DoComboStuff(cb as ComboBox)
    with cb
    .additem ...
    end with

End Sub

'And for each of the comboboxes:
Private Sub Combo1_GotFocus

    Call DoComboStuff(Combo1)

End Sub
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you don't want to call a common event or use a control array, then the answer is no.

Upgrade to VB.Net for that capability.  =)

Another way is to create a "helper" class which will receive the events of the combobox.  Here is a sample program which uses this method.  It requires code in each of the comboboxes Gotfocus events as well.

See this example:

Expand ComboBox choices while typing

Featured Post

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.

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