Problem building custom control set programatically

I need to build control sets of custom controls programatically as I need more than 200 of each control.

I used a method suggested by Jeff Tullin on this forum in 2019 but it doesn’t seem to work with custom controls.

First I built a custom class based on a rectangle control and called aBoxClass, then I created a control set with one example aBox(0) on my window. Finally I added a method:

Dim aBox() As aBoxClass
for x as integer = 1 to 10
aBox(x)= new aBoxClass
aBox(x).left = 30
aBox(x).top = 20 + 20 * x
aBox(x).visible = true
next

This is a copy of Jeff’s method using my custom class instead of a built-in class.When I run it, I get a syntax error at the first Dim line.

Can anyone tell me what I am doing wrong here?

You should be getting an OutOfBoundsException on the first line within your loop as the aBox array isn’t yet large enough to hold the item you’re trying to assign.

With aBoxClass super set to DesktopRectangle in 2022r1.1, this code compiles for me in a Window.Opening event:

Dim aBox() as aBoxClass
Dim newBox as aBoxClass
for x as Integer = 1 to 10
  newBox = new aBoxClass
  newBox.Left = 10 + (x * 10)
  newBox.Top = 10 + (x * 10)
  newBox.FillColor = &cff0000
  newBox.Width = 10
  newBox.Height = 10
  aBox.Add( newBox )
  me.AddControl( newBox )
next x

1 Like

I’m very grateful for that, Anthony. Couldn’t get it to work for a while due to a silly typing error on my part but it now works perfectly.Thank you very much for your time -Steve

1 Like