Page 1 of 1
find controls in a group
Posted: Tue Feb 08, 2011 11:06 am
by fredigertsch
How can I find all controls in a group? I have a group "gamboard" and within many groups "element". I like to find all groups "element".
How can I iterate through all objects?
Best, Fredi
Re: find controls in a group
Posted: Tue Feb 08, 2011 11:40 am
by Dixie
fredigertch...
The script below will list all the controls in a group and puts them in the variable 'myListOfControls'
Code: Select all
on mouseUp
put 1 into count
repeat for (the number of controls of grp 1) times
put the name of control count of group 1 & cr into line count of myListOfControls
add 1 to count
end repeat
end mouseUp
be well
Dixie
Re: find controls in a group
Posted: Sun Jun 16, 2013 10:52 pm
by palanolho
greetings
@Dixie,
Why do you need to concat the CR to the name of the element?
many thanks
Re: find controls in a group
Posted: Sun Jun 16, 2013 11:39 pm
by dunbarx
Hi.
Dixie was ordering the results into separate lines for readability. Step through his script and you will see. As another way to do exactly the same, consider this:
Code: Select all
on mouseUp
repeat with y = 1 to the number of controls in group 1
put the name of control y into line y of myListOfControls
end repeat
end mouseUp
I post this to show there are many ways to do things in LC, and as a new user, both will be very instructive. Please step through both scripts. Can you contruct others?
Craig Newman
Re: find controls in a group
Posted: Mon Jun 17, 2013 9:22 am
by palanolho
oh,I understood both scripts
but because I'm trying to create a list of controls to iterate them and make some changes on each, I was wondering if i would need the CR or not.
This is was I did:
Code: Select all
-- Get all Elementos of a Group
Function GetGroupElements cGroup
put 1 into i
put the number of controls of group cGroup into nrElems
put empty into tArray
repeat for (nrElems) times
put the name of control i of group cGroup into line i of tArray
add 1 to i
end repeat
return tArray
end GetGroupElements
should work, correct?
Manay thanks
Re: find controls in a group
Posted: Mon Jun 17, 2013 12:41 pm
by Klaus
Hi palanolho,
yes, should work, but "tArray" is NOT an array actually, but a CR delimited list!
I would name it: tList (or Harold)
Best
Klaus
Re: find controls in a group
Posted: Mon Jun 17, 2013 12:47 pm
by palanolho
hmmm then what can i do to have an array?
Re: find controls in a group
Posted: Mon Jun 17, 2013 1:08 pm
by Klaus
Well, depends on what you would like to see in the array

In this special case a CR delimited list will surely do!
A "simple" array with numerical keys:
Code: Select all
Function GetGroupElements cGroup
put the number of controls of group cGroup into nrElems
put empty into tArray
repeat with i = 1 to nrElems
put the name of control i of group cGroup into tArray[i]
end repeat
return tArray
end GetGroupElements
Gives:
tArray[1][field "xxx"]
tArray[2][button "yyy"]
...
Best
Klaus
Re: find controls in a group
Posted: Mon Jun 17, 2013 1:54 pm
by palanolho
Thank you very much

Re: find controls in a group
Posted: Mon Jun 17, 2013 3:47 pm
by FourthWorld
FWIW, v6.1 is in testing now and includes a new controlIDs property to return a list of controls in one line:
http://forums.runrev.com/viewtopic.php?f=4&t=15544