One thing I will point out is to name the first control to the name you want to refer to, then assign all other new members to that set. Otherwise, I couldn’t see any way of renaming the set later.
Thanks for your answers. I think I might need to get a little more specific.
I have created created a method that uses the same code for different departs. Let’s say Steel and Welding. Each dept. has 3 labels and 3 textboxes. They are named lblSteel1,…lblSteel3 and txtSteel1,…txtSteel3. So replacing the ‘Steel’ with ‘Weld’ would give the name of the Welding dept. controls.
So using code can I create a variable, that will allow me to refer to a specific control?
I suspect what you’re trying to do is something like
dim ctrl as Control = "lbl" + "steel" + "1"
programmatically to dynamically compute the name of a control and then have a reference to it
And no you really cant do that
BUT what you can do is compute the name then go through the controls on a layout & find that one with that name
dim ctrlName as string = "lbl" + "steel" + "1"
dim found as boolean
for i as integer = 0 to ControlCount() -1
if controls(i).Name = ctrlName then
// FOUND the one we wanted !!!!!!
found = true
end if
next
if not found then
// went through all the controls on the layout & did not find the one of interest
else
// we did find the one with that name
end if
use this function to get any control by it’s name. then you can set anything in the control by code
[code]Public Function GetControlByName(aWindow as window, aName as String) as RectControl
dim ctrl as RectControl
if aWindow<>nil then
For i as Integer=0 To aWindow.ControlCount-1
if aWindow.control(i) isa rectcontrol then
ctrl=RectControl( aWindow.control(i))
if ctrl<>nil then
If ctrl.Name=aName Then
return ctrl
End If
end if
end if
next
end if
A combination of Norman, Jean-Yves Pochez and Urs Geiser I got it working.
[code]dim ctrlName as string = “lbl” + “steel” + “1”
dim found as boolean
for i as integer = 0 to ControlCount() -1
if controls(i).Name = ctrlName then
// FOUND the one we wanted !!!
found = true
end if
next
if not found then
// went through all the controls on the layout & did not find the one of interest
else
// we did find the one with that name
end if[/code]
ContainerControls have longer names, as you could see with Introspection.
However, their name ends up by the name you gave them in the IDE, so you can do something like :
[code]dim ctrlName as string = “lbl” + “steel” + “1”
dim found as boolean
for i as integer = 0 to ControlCount() -1
if right(controls(i).Name, len(ctrlName)) = ctrlName then
// FOUND the one we wanted !!!
found = true
end if
next
if not found then
// went through all the controls on the layout & did not find the one of interest
else
// we did find the one with that name
end if[/code]
this is a way to get the containercontrols in a given window.
it’s not very efficient because it iterates on all the objects of the application
but it works !
others (I dont remember who but search for containercontrol on this forum, Beatrix if I recall) prone the use of notificationaction and receiver to act what controls are in the widow, then store them on a private list.
[code]Public Function ContainerControls(extends w as Window) as ContainerControl()
'get a list of all the container controls in a window
dim theList() as ContainerControl
dim o as Runtime.ObjectIterator = Runtime.IterateObjects
while o.MoveNext
if o.Current isA ContainerControl and ContainerControl(o.Current).Window is w then
theList.Append ContainerControl(o.Current)
end if
wend
return theList
End Function
[/code]
[code]Public Function ControlOrContainerControl(Extends win As Window, index As Integer) as Object
’ get the nth control or container control in a given window
I posted a much simpler method based on the one you posted before. Container Controls names are available in a simple iteration, but they have a bunch of stuff before that’s all, so you look for the right part of the name.