Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Array Problem 1

Status
Not open for further replies.

Kazim

Programmer
Jul 23, 2001
26
0
0
GB
Within my program I use a control array of a custom user defined control. One of these controls with the index of 0 exists at program start. Others are added and removed during program use.

I am easily able to add new controls, and place them in the correct position using the Load command, and by using a gloabl variable for the index counter.

The problems arise when I need to remove one of the controls. Removing it is not a problem with the Unload command, however, the control array is now missing an element, so that trying to loop through the items causes an error.

As you will imagine, similar errors crop up all the time as items are added and removed and as other functions within the program try to work with the control array.

Can anyone suggest a method of doing this that will remove this problem? I am thinking along the lines of some method of "ReDIMing" the control array, but I have no idea if this can be done or not.

Any help at all would be greatly appreciated.
 
If you are 'looping through the items' in a for...next loop such as this:

For a& = Lbound(CtrlName) to Ubound(CtrlName)

then you will run into problems with missing items.

Have you tried looping through like this:

For Each Obj in CtrlName
(do stuff)
Next Obj

This will only cycle through existing items in your control array.


- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Yes indeed I have, and it works nicely for the control array, however, the control array is a 0 based array, and each item in the control array is linked to a button in a toolbar.

The buttons in the toolbar are a 1 based array. To get over this I created the first user control, with an index of zero, and made it invisible. By means of the "For i = " loop, I could keep this item out of use when using the buttons on the toolbar.

Can you see a way to connect the two together, using the "For Each.." method?

When I try t use this method, I find that the extra item in the control array (Item zero) always seems to cause a problem. in some way, which was why I tried using the other method.
 
As the first line in the loop, put

If (Obj.Index <> 0) Then
(do stuff)
End If

This will skip over element 0.


- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Gaaah!!! B!%$&y hell!

Yes, thats perfect! Now I need to go and kick myself really hard for just not even thinking of that!

Thanks very much Andy, I feel a right dumbass now! My only excuse is that sometimes we dont see the wood for the trees!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top