Here’s a slightly more succinct method I just worked up:
Private Function ControlSetLastIndex(c as RectControl) As Integer
var lastIndex as Integer = -1
for each r as RectControl in c.TrueWindow.Controls
if r.Name = c.Name then
lastIndex = lastIndex + 1
end if
next r
Return lastIndex
End Function
Called as:
var lastIndex as Integer = ControlSetLastIndex( PushButton1(0) )
Note that you must pass it a valid instance from the ControlSet.
If you want it as an extension of RectControl, place in a module:
Public Function ControlSetLastIndex(extends c as RectControl) As Integer
var lastIndex as Integer = -1
for each r as RectControl in c.TrueWindow.Controls
if r.Name = c.Name then
lastIndex = lastIndex + 1
end if
next r
Return lastIndex
End Function
Call as:
var lastIndex as Integer = PushButton1(0).ControlSetLastIndex