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
Referencing Objects of the Same Name
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Referencing Objects of the Same Name
You could use a custom property, but will still run into the same (modest) barrier I think you alluded to in the above quote. You can:Interesting idea about setting the object Label to a unique name that can later be references by running though the list of all objects. Though with Buttons, using the object's Label isn't practical. Couldn't the same thing be done by creating and referencing a Custom Property for each object?
select btn 3, or
select btn "buttonName", or
select btn id idValue
but you cannot:
selet btn "labelReference" or
select btn "customPropertyReference"
You would have to run a loop that checks these properties and acts accordingly:
repeat with y = 1 to the number of buttons -- uses a native control reference
if the label of btn y = "someLabelInstance" then doStuff --uses a property reference
end repeat
Craig Newman
Re: Referencing Objects of the Same Name
Wait a sec!
put "Hello World" into fld "field3"--yes that works
repeat with x=1 to 3
put "Hello World" into (line & x) of fld "field3" --I remembered this time
end repeat
Is that what you mean townsend?
Simon
Line1, Line2, Line3 ... Line1
Code: Select all
put "hello world" into fld "test" 3
put "hello world" into fld "test"[3]
put "hello world" into fld 3 "test"
repeat with x=1 to 3
put "Hello World" into (line & x) of fld "field3" --I remembered this time

end repeat
Is that what you mean townsend?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Referencing Objects of the Same Name
Code: Select all
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
Re: Referencing Objects of the Same Name
"Referencing Objects of the Same Name"
Wild goose...
"Referencing Objects with Similar Numerically Incremented Name"
Glad you got it working!
Simon
Wild goose...
"Referencing Objects with Similar Numerically Incremented Name"
Glad you got it working!

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!