Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    L.A., California
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding Control Array (VB6)

    Hi All,

    Does anybody know of a way to add a control ARRAY at runtime?
    I'm adding a Line control, but want it to be a control array.
    Here's how I'm adding the line: Me.Controls.Add "VB.Line", "lineXXX"
    This works great, but can't make it an array or give it an index property.
    Any ideas? I'm not averse to using the API.
    Thanks,

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adding Control Array (VB6)

    I don't know if you are still looking for an answer to this question.

    It is not possible to create a control array from scratch entirely in code. You will need to create the first element in design mode and set its Index property to 0. This item can be hidden if you wish.

    Say that you have created a line called MyLine with index 0 in design mode. You can create new elements as follows:

    Dim i As Long
    For i = 1 To 10
    Load MyLine(i)
    MyLine(i).Y1 = MyLine(0).Y1 + 144 * i
    MyLine(i).Y2 = MyLine(0).Y2 + 288 * i
    MyLine(i).Visible = True
    Next i

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Location
    L.A., California
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding Control Array (VB6)

    Thanks for the response HansV. I arrived at the same conclusion myself. I was hoping there would be a slick API way to do it.

    Ever see one of those programs where you have 2 listboxes full of items, and you need to equate an item in one with an item in the other? This is usually done for data mapping purposes. You click on an item in each listbox, tap a button, and a line appears between them. Well, I wrote a VB6 class to manage that task, and I wanted the user to not have to add a line to his form, but rather the class would do it all. Alas, no luck. The user only needs a form with 2 listboxes, a line array and link/unlink buttons, and it works. If anybody is interested, reply or e-mail me and I'll post a sample project.

    Thanks again for trying.

  4. #4
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding Control Array (VB6)

    I was going to create a new post for this but couldn't work out how to link to posts, therefore a reply will have to do for now:

    Using Hans' method of adding controls to a control array, does anyone know how to remove controls from the array? I'd like to remove all of the controls so either a complete "destructor" for all runtime made controls of that name or a single remove function that I can loop through the array's index will do.

    I found the frm.object.remove ("obj name") command, but couldn't get it to work with an array.

    Any help would be much appreciated.

    Regards,

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Adding Control Array (VB6)

    1. Each post has a number, displayed below the subject. for instance, the post at the top of this thread has number 298772. You can create a link to it in two ways (also see <!help=19>Help 19<!/help>):

    <!t>[post#=298772]<!/t> results in <post#=298772>post 298772</post#>
    <!t>[post=Adding control arrays,298772]<!/t> results in <!post=Adding control arrays,298772>Adding control arrays<!/post>

    2. Just as you can use Load MyLine(i) to create a new instance, you can use Unload MyLine(i) to destroy an existing instance. Using the same example as in my reply higher up in this thread:

    Dim i As Long
    For i = 10 To 1 Step -1
    Unload MyLine(i)
    Next i

  6. #6
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding Control Array (VB6)

    Wow, thanks Hans, both problems solved in one hit.

    Next time I need to link to such a post as <!post=Adding control arrays, 298772>Adding control arrays<!/post> it will be no trouble at all.

    The removing arrays code works like a treat, and was so easy to implement!

    Thanks for your help, and such speedy help it was too!

Posting Permissions

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