Re: Referencing Objects of the Same Name
Posted: Sun Dec 22, 2013 9:26 pm
Just to be clear, as has been intimated before in this thread, you can reference each control by its ordinal number - which is defined by the layer on which it resides.
field 1 is the field nearest to the lowest layer on the card. (ie the field nearest to layer 1)
field 2 is the field next nearest to layer 1
button 1 is the button nearest layer 1, etc etc
for example:
layer 1 has a button
layer 2 has a field
layer 3 has another field
layer 4 has another button
layer 1 = button 1
layer 4 = button 2
layer 2 = field 1
layer 3 = field 2
put "hello world" into field 2
will put the "hello world" value into the field second nearest to layer 1 on the card, regardless of what it is named. To reference a field or other object by name the objects should all have an appropriate name. Naming things consistently will mean you have the best of both worlds, a "robust" naming convention that lets you identify each object granularly, while always being able to loop through the objects according to ordinal (ie its layer relative to layer 1)
If, as you say you have been naming things "Line1", "Line2" then you can alternatively
repeat with i = 1 to the number of buttons of this card
if there is a button ("Line" & i) then
-- do stuff with button ("Line" & i)
end if
end repeat
field 1 is the field nearest to the lowest layer on the card. (ie the field nearest to layer 1)
field 2 is the field next nearest to layer 1
button 1 is the button nearest layer 1, etc etc
for example:
layer 1 has a button
layer 2 has a field
layer 3 has another field
layer 4 has another button
layer 1 = button 1
layer 4 = button 2
layer 2 = field 1
layer 3 = field 2
put "hello world" into field 2
will put the "hello world" value into the field second nearest to layer 1 on the card, regardless of what it is named. To reference a field or other object by name the objects should all have an appropriate name. Naming things consistently will mean you have the best of both worlds, a "robust" naming convention that lets you identify each object granularly, while always being able to loop through the objects according to ordinal (ie its layer relative to layer 1)
If, as you say you have been naming things "Line1", "Line2" then you can alternatively
repeat with i = 1 to the number of buttons of this card
if there is a button ("Line" & i) then
-- do stuff with button ("Line" & i)
end if
end repeat