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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control array's ubound

Status
Not open for further replies.

markask

Programmer
Apr 28, 2005
167
GB
Hi,

When drag a control of a control array, how to know the control array's ubound in DragDrop()?

This not works:
Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)
Print Source.ubound

Thank you in advance.
 
I don't think that's going to be easy, since you can index the controls the way you want:

ctl1(0)
ctl2(3)
ctl3(6)

What's the upper bound of this array? You'd say it would be 2, but if you index the control array with 2 you'll get an error. Would it be 6 then? That's very difficult to find out without you keeping track of the controls that have been created. Besides; the upperbound being 6 does not mean that there's a 5 too.

Maybe you should create an array of integers in which you keep track of the control indexes that have been created.....

Greetings,
Rick
 
Thank you.
I have just tested that if I only got Image1(0), then
Load Image1(3)
Print Image1.UBound
will disply 3
 
That's rather dangerous in my opinion, since u would then assume that there's a 1 and a 2 too, which may or mat not be the case.....

Greetings,
Rick
 
Here's two quotes from the MSDN on the UBound property:
MSDN said:
Returns the highest ordinal value of a control in a control array.

UBound is equal to the Index property value of the last control in the array.

Sounds like it is working just like it is supposed to.

Have you tested to make sure that it doesn't also create instances 1 and 2 when you create 3? It may be quietly filling in the missing elements without telling you.

If there ARE gaps in the control array, then you would probably be better off using a for each loop.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
A control array is a very different beast from an array of controls. One thing it doesn't do is 'fill in' missing elements. LazyMe's repeated warnings should be heeded.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top