This question is about better understanding what I am doing:
I want to iterate over all the controls on a window, and used the example from the wiki with a for next loop.
That works, I would expect the following code to work too.
But it doesn’t, could somebody elaborate why?
//
dim oRectControl as rectControl
// tried this: for each oControl as control in self.control
for each oControl as control in window.control
// Is the control a RectControl?
if oControl isa RectControl then
// Cast it.
oRectControl = RectControl(oControl)
// do something
end if
next
What Michel said. Window.Control does not return an array so it cannot work with For Each. It is a method that takes an index parameter and returns a control.
as Paul indicated the “zero-based array” text should be removed
It should read that way: Window.Control Method
Window.Control (index As Integer) As Control
The property is read-only. The zero-based array of the controls in the window.
[quote=230783:@Paul Ross]Thank you both for the reply.
I must be reading the documentation wrong.
It states: The zero-based array of the controls in the window.
right above the notes.
@Paul Lefebvre : Is there no iterator for these controls?[/quote]
It is a pseudo array, not a real one. As I tried to explain, there is no ubound.
Because something has an index does not mean it is an array in the sense of Dim myArray() as RectControl. Another excellent example is ControlSets, which are addressed like an array, except they can be non contiguous (1,2,4,5), and do not have an ubound.
But hey, if you absolutely want to use an array of controls, you can do something like
Dim MyArrayOfControls(-1) as RectControl
For i As Integer = 0 To Self.ControlCount-1
MyArrayOfControls.append(Window.Control(i))
Next
At the end of that routine, you can use myArrayOfControls() with for each, get its ubound, and so on…
Yes, there are many “properties” that are listed in the classic wiki docs that are not properties at all. Some are getter/setter pairs (using Assigns) others are just flat-out methods like this one. I have no idea why it was done that way back in the day, but I don’t like it either. It is confusing.
Unfortunately, it is not practical to go through the wiki and move/change all the ones that are not correct.
However, all the new docs for the new framework (in the Dev Center) precisely state what the member is: property or method. This way you’ll know what you can find in the debugger and what can be properly overridden.
I haven’t run into the problem with the ControlSets, have not used them so far.
Thank you for you’re clarification, which I understood.
I was trying to get it clear in my mind on why something works this way or that way.
There is this, (dumb I know), wrong wiring in my mind that if i read a manual I assume (keyword) it is correct.
And then try different things to better my understanding of the tool/language.
And the last couple of weeks I am trying to get a better understanding on when to use for next or for each.
So thank you and Eli for helping me with clarifying this.
[quote=230818:@Paul Ross]I was trying to get it clear in my mind on why something works this way or that way.
There is this, (dumb I know), wrong wiring in my mind that if i read a manual I assume (keyword) it is correct.
And then try different things to better my understanding of the tool/language.[/quote]
Never hesitate to ask away. I do it often myself.
And never be afraid to experiment. Sometimes the best way to grasp a concept is through trial and error in a test project where you cannot break anything