How do we parse through the members of a Control Array?

Opened a new thread on this since it’s not specific to Web use.

In trying to debug the cause of the NOE when accessing my Control Arrays, I simply tried to loop through the Text values of the members. As soon as I tried to access array member 1, I get an NOE. I then tried to get the Ubound for the Control Array to only step through the existing members but Ubound is not an option …

I know I’ve been living in Visual Studio and XCode for the last 4 months, but, no Ubound on a Control Array?

Hi Tim,

Yes, you don’t have a ubound for Control Sets. You need to keep a count of members yourself when you add or remove them. I don’t know about your NOE, but check it’s of the type you want with ISA and then if it is, cast accordingly.

Regards - Richard.

Thanks, Richard, but the reason that I was trying the Ubound trick was because my array of 5 controls (0-4) is throwing an NOE as soon as I stepped from 0 to 1. Basically:

For x = 0 To 4
    MemCheck = MemCheck + Val(pmCount(x).Text)
Next

Accessing 0 is good, but as soon as x becomes 1, poof - NOE.

I seem to recall that control arrays don’t necessarily go in order with no holes. Xojo renamed them to Control Sets to help mitigate this confusion https://documentation.xojo.com/topics/user_interface/desktop/desktop_controls/control_sets.html

If I were implementing this, I would use ContainerControl and manage my own array. You may find more luck with this method.

It turns out that if the members of the control set (thanks, Tim) aren’t visible, they don’t exist. If I keep track of how many rows are visible, the logic works …

Usually, the way to replace the missing UBound function was to use a code like this:

var i as integer
do
try
var cnt as MyControlArray=MyControlArray(i)
catch
return i
end try
i=i+1
loop

(sorry for possible bugs, I don’t remember well; it was months/years ago that I needed this)
This is no longer doable in Xojo because the order/hole-free is not guaranteed anymore?

This will fail on Control Sets with holes in them. According to Tim, making a control invisible creates a hole. Removing an item also leaves a hole. Control Sets are not arrays and that is covered in the documentation I linked.

So it changed, because that was doable 5 or 10 years ago.

What’s the proper way to get all items of a controls set now? Keep a property array to the window and add/remove items along the real control?