Bug? For - Next Loop fails with WebLabel array

I have known-good code with a For / Next loop working with an integer iteration that is used to select the array member to add the text to a String variable.

For some reason this fails with a WebLabel array.

This code works:

// g() has several members, all WebLabel controls.
Var s As String
Var g As Integer

For g = 0 To 7
s = s + " " + w(g).Text
Next

Var js As String = “navigator.clipboard.writeText('” + s + “');”
ExecuteJavaScript(js)

THIS code FAILS:

Var s As String

For Each b As WebLabel In g
s = s + " " + b.Text
Next

Var js As String = “navigator.clipboard.writeText('” + s + “');”
ExecuteJavaScript(js)

I copied the same pattern of logic that I saw with String arrays being used in For Each - Next loops, and I’m wondering if this is a bug that I’m encountering.

It could be that I’m sleep-deprived and am missing something ridiculously obvious, or this could be a bug. Thanks to anyone helping restore my sanity on here.

Can you give more information about “this code fails”?
What do you see?
Or you can provide a sample code to easily see what you see.

I am getting errors, and the logic I’m using is patterned after String array code.

You’re seeing that because control sets don’t implement the iterable functionality. Additionally, the framework still gives you no way of determining how many controls are in a set, such as by using myControlSet.LastIndex.

One way around this is to use a property something like myControlSetLastIndex As Integer = -1 then in the control set’s Opening event you add one to that property. That would then allow you to write the following for iteration:

for index as Integer = 0 to myControlSetLastIndex
  var current as myControlSet = myControlSet(index)
  '// do something here...
next

Or you can iterate all controls on the WebPage/Window/Container:

for each o as Object in self.Controls
  if o isa myControlSet then
    var label as myControLSet = myControlSet(o)
    '// do something here...
  end if
next

Ah, makes sense. I’m surprised that control sets don’t implement iterable functionality, considering that such functionality exists with folders / children and variable sets such as String and Integer.

I know exactly how many WebLabel controls I have in the array, so at least I don’t have to sort that out.

I implement it that way to futureproof. I can add or remove labels as needed without modifying code.