find controls in a group
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 38
- Joined: Mon Jan 03, 2011 5:42 pm
find controls in a group
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
How can I iterate through all objects?
Best, Fredi
Re: find controls in a group
fredigertch...
The script below will list all the controls in a group and puts them in the variable 'myListOfControls'
be well
Dixie
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
Dixie
Re: find controls in a group
greetings
@Dixie,
Why do you need to concat the CR to the name of the element?
many thanks
@Dixie,
Why do you need to concat the CR to the name of the element?
many thanks
Re: find controls in a group
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:
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
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
Craig Newman
Re: find controls in a group
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:
should work, correct? 
Manay thanks

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

Manay thanks
Re: find controls in a group
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
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
hmmm then what can i do to have an array?
Re: find controls in a group
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:
Gives:
tArray[1][field "xxx"]
tArray[2][button "yyy"]
...
Best
Klaus

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
tArray[1][field "xxx"]
tArray[2][button "yyy"]
...
Best
Klaus
Re: find controls in a group
Thank you very much 

-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: find controls in a group
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
http://forums.runrev.com/viewtopic.php?f=4&t=15544
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn