find controls in a group

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
fredigertsch
Posts: 38
Joined: Mon Jan 03, 2011 5:42 pm

find controls in a group

Post by fredigertsch » Tue Feb 08, 2011 11:06 am

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

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: find controls in a group

Post by Dixie » Tue Feb 08, 2011 11:40 am

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

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: find controls in a group

Post by palanolho » Sun Jun 16, 2013 10:52 pm

greetings

@Dixie,

Why do you need to concat the CR to the name of the element?

many thanks

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: find controls in a group

Post by dunbarx » Sun Jun 16, 2013 11:39 pm

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

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: find controls in a group

Post by palanolho » Mon Jun 17, 2013 9:22 am

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: find controls in a group

Post by Klaus » Mon Jun 17, 2013 12:41 pm

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

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: find controls in a group

Post by palanolho » Mon Jun 17, 2013 12:47 pm

hmmm then what can i do to have an array?

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: find controls in a group

Post by Klaus » Mon Jun 17, 2013 1:08 pm

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

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: find controls in a group

Post by palanolho » Mon Jun 17, 2013 1:54 pm

Thank you very much :)

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: find controls in a group

Post by FourthWorld » Mon Jun 17, 2013 3:47 pm

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply