Results 1 to 14 of 14

Thread: [RESOLVED] Dim WithEvents for an command button array

  1. #1

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Resolved [RESOLVED] Dim WithEvents for an command button array

    What I want to do is to create a dynamic button array and use WithEvents for the events for the array. How can one do this?

    What I have Tried is

    Dim WithEvents cmdButtons as CommandButton


    This works as it should for one button but


    Dim WithEvents cmdButtons() as CommandButton


    is a VB no-no...

    I am using Controls.Add to create the buttons and what I want is the events sub to handle the button array, like such:

    Private Sub cmdButtoms(Index)

    How to?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Dim WithEvents for an command button array

    The easiest way is to create a template control at design time (which you don't actually use), and use Load to create copies of it.

    Alternatively, see the article about this in our Classic VB FAQs (in the Misc. section), which explains other methods.

  3. #3

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Dim WithEvents for an command button array

    Yes, I am aware of that method but I wanted to do a little something different this time... It helps the learning experiences... Any ideas?

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Dim WithEvents for an command button array

    There are at least two work-arounds described in the WithEvents FAQ article.. I haven't seen any others (if I had, I would have added them there).

  5. #5

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Dim WithEvents for an command button array

    Where is this "WithEvents FAQ" article?

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Dim WithEvents for an command button array

    Go up a level in the forums, VB FAQs section. Here is the direct link
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Dim WithEvents for an command button array

    Thanks.

  8. #8

  9. #9

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Dim WithEvents for an command button array

    Yes, not directly I found out.

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Dim WithEvents for an command button array

    MartinLiss, one can't. si_the_geek tried to direct poster to a method to workaround the problem, by using an implementation. I have used that same procedure before with satisfactory results.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Dim WithEvents for an command button array

    I don't see why anyone would want to take the troble to use a workaround instead of using the method si described in post#2. I would say however that there's no reason why the "template" control can't be used like any of the ones that are Load-ed. You just need to make it Visible/not Visible rather than loading/unloading it.

  12. #12

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Dim WithEvents for an command button array

    Sometime one want to see if another way can be done "Just Because..." That is how new things and ways are found. Not an issue, just wanted to see if I was overlooking something.

  13. #13
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Dim WithEvents for an command button array

    Well, here is one scenario (not the best example). A class adds controls to a host form, but the host form isn't required to provide a template control. What kind of controls woulld the class add? I don't know, maybe a few pictureboxes to act as sizing handles? That is just an example of course, there could be other reasons for the workaround...
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  14. #14

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width