How to obtain the "ubound" of a control set ?

Hi
The tilte says it all.
Control sets are not arrays, so I was wondering if there is any way to obtain the dimension by code,

thanks

basically… you don’t… at least not directly

I never tried to loop through the controls with
Dim c As Control
For i As Integer = 0 To Self.ControlCount-1
c = Window.Control(i)
If c IsA [my kind of control]Then

I use to count the instances of my controls myself
with an own variable when I instantiate one of them:
CountOfMyControls = CountOfMyControls +1

(You surely will find a shorter Name for the variable)

And don’t forget to count down when you close one of them

go up until you find an item which is nil.

Attention : a control set can have “holes”, if a member has been deleted. So one nil does not mean this is the end of members. If is probably wise to go on for more, to make sure there it was not a hole.

Because Control Set indices are not consecutive use something like these extension methods (in a Module, Global scope)

[code]Function getControlSetIndices(extends w As Window, name As String) As integer()

dim indices() As integer

dim c As Control
for i As integer = 0 to w.ControlCount - 1

c = w.Control( i )

if c.Name = name and c.Index >= 0 then indices.Append c.Index

next

indices.Sort

return indices

End Function[/code]

[code]Function getControlSetUbound(extends w As Window, name As String) As integer

dim indices() As integer = w.getControlSetIndices( name )

if indices.Ubound = -1 then
return -1
else
return indices( indices.Ubound )
end

End Function[/code]

Call them like

dim i() As integer = getControlSetIndices( "myButtonSet" ) dim i() As integer = getControlSetIndices( myButtonSet(0).Name ) dim i() As integer = self.getControlSetIndices( "myButtonSet" ) dim i() As integer = myContainerControl.getControlSetIndices( "thatButtonSet" )

If possible I would recommend to subclass the control and use the Open event to add itself to a shared array on the class and the Close event to remove itself from it.

There is another way : place the controls in an array, and each time a member is removed, change the index for the controls, so they keep the same index as in the array. You then have an ubound.

Of course it is best to have your own remove method in order to do the controls housecleaning.