Solved

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

Posted on 2004-10-27
146 Views
Last Modified: 2010-05-02
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?
0
Question by:superbeast23
    3 Comments
     
    LVL 32

    Expert Comment

    by:Erick37
    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
    0
     
    LVL 85

    Accepted Solution

    by:
    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.  =)

    ~IM
    0
     
    LVL 32

    Assisted Solution

    by:Erick37
    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
    http://www.vb-helper.com/howto_expand_combobox.html
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: JavaScript Coding - Massive 12-Part Bundle

    Regardless of your programming skill level, you'll go from basics to advanced concepts in a vast array of JavaScript subjects including Sammy.js, Agility.js, Ember.js, Node.js, jQuery, AJAX, Extjs, AngularJS, Knockout.js, and JSON.

    Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now