Instantiate Control Name with Dynamic Index?

Hey everyone I have a question that I can’t seem to work and/or may be hitting a newbie design flaw.

I need to dynamically add an index number to a instantiated control name so every time I run it a “NewContainerControlX” is created as the “X” being a Number.

I have ran into the wall as I created a string name with index that I desire but then of course the variable is a string in which doesn’t fly since the control is a Container Control. Can I change that and/or how can I accomplish this another way?

Any ideas would be appreciated and sorry if this question sounds silly. :slight_smile: Thanks

In RS they were called “Control Arrays”. In Xojo, they are “Control Sets”. You can’t have a set with each member having a different name. They must all have identical names. But each time you create a new member it will have the next sequential index number. So that basically accomplishes what you want. Have a look at Control Sets in the docs.

Thanks Roger for the reply. I tried using Control Sets in the beginning of this and couldn’t since my controls are not like (textfield and popupmenu). That is why I am using Container Controls which are working nicely. I am just having trouble accessing each individual dynamic instance since they all of the same name. I am also watching Paul’s webinars hoping to gain more on this topic.

Thanks again!

Append your containercontrols into an array.

dim myContainers() as myContainerControl
dim c as myContainerControl
c = new myContainerControl
myContainers.Append c
c= new myContainerControl
myContainers.Append c
myContainers(0).TextField1.Text = "First control"
myContainers(1).TextField1.Text = "Second control"

Except make myContainers a property of the window, not dim’d locally.

Thanks Tim I had been trying that but I just found my DA moment watching Paul’s webiner on container controls. I had not been setting mycontainers as a property where I think my issue was as you suggested. Phew and thank you again!