control set ubound?

For some reason I cannot access ubound of a control set. Here’s my code:

Is it even possible or do I need to go another route?

[code]dim i as integer

for i = 0 to ubound(mycontrolset)

my code here…

next[/code]

Control Sets are not arrays, so they cannot use Ubound. You’ll need to keep a count of the controls you’ve added some other way.

Okay I will do that, Thank you Paul for your help…

Or loop until you get nil when increasing index.

Won’t help you if you have non-continuous indices.

I have an example project which uses extension methods and can handle non-contiguous indices.
This example relies on index = 0 always existing:-

Example project (.rbp)

In this a loop through a control set of textfields called txtMyText looks like:-

  Dim intAt as integer
  
  if self.txtMyText(0).MyUbound <> ( self.txtMyText(0).MyCount - 1) then
    self.txtMsg.Text = "Control indexes are not contiguous" + EndOfLine
  end if
  
  For intAt = 0 to self.txtMyText(0).MyUbound
    if self.txtMyText(intAt) <> nil then
      self.txtMsg.Text = self.txtMsg.Text + "Item(" +str( self.txtMyText( intAt ).index ) + ").index = " + str( self.txtMyText(intAt).index ) + EndOfLine
       self.txtMyText(intAt).text = "Index=" + str( self.txtMyText(intAt).index )
    end if
  next intAt
  
  RETURN

The Ubound extension method looks like…

  Function MyUbound ( extends ctl as control ) as Integer

  Dim intAt as integer
  Dim intCount as integer
  Dim intUbound as integer
  
  intCount = 0
  intUbound = -1
  
  For intAt = 0 to ( ctl.Window.ControlCount - 1 )
    
    if ctl.Window.Control( intAt ).Name = ctl.Name Then
      intCount =  intCount + 1
      
      if intUbound < ctl.Window.Control( intAt ).index  then
        intUbound = ctl.Window.Control( intAt ).index
      end if
      
    end if
    
  next intAt
  
  
  RETURN ( intUbound )

The MyCount method is similar, just returning the intCount value