Results 1 to 6 of 6

Thread: help Array with events

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Location
    Toledo, OH
    Posts
    785

    help Array with events

    Hi, I need to declare an array which will be used to add controls to a form such as this

    vb Code:
    1. Public picBatch() As Control
    2. Public intControlIndex As Integer
    3.  
    4. intControlIndex = UBound(picBatch) + 1
    5. ReDim Preserve picBatch(intControlIndex)
    6.  
    7. Set picBatch(intControlIndex) = Controls.Add("VB.PictureBox", "PicBatch_" & CStr(intControlIndex))



    I need to then assign my own tags.

    IE. picBatch(1).AtStart = true

    how do I do this?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: help Array with events

    Its not an easy solution but it is possible.
    See penagates FAQ and code examples on the topic.

    http://www.vbforums.com/showthread.php?t=372811
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Location
    Toledo, OH
    Posts
    785

    Re: help Array with events

    Quote Originally Posted by RobDog888
    Its not an easy solution but it is possible.
    See penagates FAQ and code examples on the topic.

    http://www.vbforums.com/showthread.php?t=372811

    can this be done with an array declared as a picturebox?

    perhaps i can just make a new variable that links with the array variable and use events?

    sorry I have no knowledge of making variables with events.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: help Array with events

    I would think so but I didnt write it so I may not be the best to answer you. Perhaps send PG a pm with a link to this thread.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: help Array with events

    Quote Originally Posted by TheUsed
    can this be done with an array declared as a picturebox?
    Yes: you need to use the second solution (after the divider in that post).

    Make an interface class which defines method stubs for every picturebox event which you need to handle. Ensure that each method has an argument which is the reference to a picturebox.

    Make a class which contains: (1) a callback property declared using the interface type, which will reference your form, and (2) a reference to a picturebox object declared using WithEvents. In this class, handle each event which you declared in the interface, and in each event handler, call the corresponding method using the callback property you created in (1).

    Implement that interface in your form; you can use the picturebox argument of each method to determine where the event was fired from. (Make sure you pass this argument from the event wrapper class!) In the Form_Load event, you can create the array of references to wrapper classes. Set the callback property to 'Me'. This is shown in the FAQ post.

    I'd write an example of this exact technique for you, but it's been so long since I used VB6 that I'd get the syntax wrong and mislead you. Hopefully, if you need, someone else can take what I described and create code to do it.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Location
    Toledo, OH
    Posts
    785

    Re: help Array with events

    im affraid this is more than I know when it comes to VB6, any way I can get some code examples?

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