Select Group
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Select Group
Hello,
Currently i got 10 groups and what i want to do is that if i click on the 1st group i will receive value 1 and if
i click on 3rd group i will receive value 3 and if i click on 4th group i will receive value 4.
And i want to store the value into a variable.
As my group is created by looping so i have quite alot of group ~ ~
Anyone know the solution for this?
Thanks!!
Currently i got 10 groups and what i want to do is that if i click on the 1st group i will receive value 1 and if
i click on 3rd group i will receive value 3 and if i click on 4th group i will receive value 4.
And i want to store the value into a variable.
As my group is created by looping so i have quite alot of group ~ ~
Anyone know the solution for this?
Thanks!!
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Select Group
Hi jwtea,
several ways, the best depends your context
1. A function
getting the layer for each group
sort it by layer ascending
first line = first group etc...
2. Using name of groups when you create them, something like "myGroup_1,myGroup_2, etc..." and geting the string after "_" when you click one group
Best regards
Jean-Marc
several ways, the best depends your context
1. A function
getting the layer for each group
sort it by layer ascending
first line = first group etc...
2. Using name of groups when you create them, something like "myGroup_1,myGroup_2, etc..." and geting the string after "_" when you click one group
Best regards
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 9663
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Select Group
I like Jean-Marc's second idea.
It would be easy to do because when you create a new control, that control is the "last" control.
However, as of v6, the keyword "last" is not stable for groups.
I know.
So has anyone learned that this peccadillo has been fixed in v. 8/9? I just did a short test, and it seems to work.
Craig Newman
It would be easy to do because when you create a new control, that control is the "last" control.
However, as of v6, the keyword "last" is not stable for groups.
I know.
So has anyone learned that this peccadillo has been fixed in v. 8/9? I just did a short test, and it seems to work.
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Select Group
I use this method often, and I used to name the groups as a single word with a trailing number. But a tip on the forums some years ago made me change my method -- I separate the name and the number with a space:2. Using name of groups when you create them, something like "myGroup_1,myGroup_2, etc..." and geting the string after "_" when you click one group
myGroup 1
myGroup 2
myGroup 3
This makes is very easy to extract the number. It will be "the last word of the short name of the target".
Another way to track the number of the group is to assign a custom property to each group. The property (I'll call it "cNum") will contain just the number you want to retrieve. Then you can "get the cNum of the target" to find out its numerical reference.
Using "the target" may not be appropriate, it depends on how your scripts are set up. You may need "the owner of the target" or something else.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Select Group
When you were using the previous method, say, myGroup1, wouldn't "the last character of the short name of the target" suffice to extract the number easily?
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Select Group
Yes, up until 10.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9663
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Select Group
If I have to go past 10 in any situation, I just say "many".
Craig
Craig
Re: Select Group
Ahhhh, I see. That makes more sense.
Re: Select Group
Hello thanks all for your replies!!
But how can i create different name for each group as i'm using loop code to create them??
But how can i create different name for each group as i'm using loop code to create them??
-
- VIP Livecode Opensource Backer
- Posts: 9663
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Select Group
As above, in your loop, set the name of the "last" group to some string && the number of groups:
Now this may require some filtering, especially if other groups are created in between runs of your loop. Just be careful there.
Craig
Code: Select all
set the name of last group to "myGroup" && the number of groups
Craig
Last edited by dunbarx on Fri May 04, 2018 5:43 am, edited 1 time in total.
Re: Select Group
Thanks Craig!!!
By the way,
let's say i got 10 groups right and inside each group got a unique number field and a widget.
So if i click on the 1st group widget, the unique number field value inside the 1st group will be put into a
field call holding field.
And if i click on the 3rd group widget, the unique number field value inside the 3rd group will be put into the same field call holding field.
Can i know what the code for the above function??
Thanks Craig, appreciated alot!!
By the way,
let's say i got 10 groups right and inside each group got a unique number field and a widget.
So if i click on the 1st group widget, the unique number field value inside the 1st group will be put into a
field call holding field.
And if i click on the 3rd group widget, the unique number field value inside the 3rd group will be put into the same field call holding field.
Can i know what the code for the above function??
Thanks Craig, appreciated alot!!
-
- VIP Livecode Opensource Backer
- Posts: 9663
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Select Group
Hmmm.
Are your 10 groups and their children named in order? Or do they possess a common property? You really need a way to discriminate among them. So you could name your groups after animals or fruit. And then you also have to associate the widgets and unique number field in like kind. This preparation is critical to writing code that can make sense later on, and keep that code itself simple and readable. So let us assume that all three of these controls (widget, uniqueNumberField and group) all have a common property. Let us say they are all numbered like Jacque mentioned:
group "myGroup 4"
widget "myWidget 4"
field "uniqueNumberField 4"
In the card script:
So, again, have you ordered your groups and the controls of interest inside them in a fashion that allows them to fall into "natural" sets with common properties? If not, do so now, and always do so in the future.
Write back if none of this makes sense.
Craig
Are your 10 groups and their children named in order? Or do they possess a common property? You really need a way to discriminate among them. So you could name your groups after animals or fruit. And then you also have to associate the widgets and unique number field in like kind. This preparation is critical to writing code that can make sense later on, and keep that code itself simple and readable. So let us assume that all three of these controls (widget, uniqueNumberField and group) all have a common property. Let us say they are all numbered like Jacque mentioned:
group "myGroup 4"
widget "myWidget 4"
field "uniqueNumberField 4"
In the card script:
Code: Select all
on mouseUp
put word 2 of the short name of the target into tNumber
put field "uniqueNumberField" && tNumber into field "holding field"
end mouseUp
Write back if none of this makes sense.
Craig
Re: Select Group
Hello Craig, the reason why all my group and field got same property because my code is written as below.
Below is my preopencard script
PS: tArray is fetching my json object
PS: I had tried to use your code but it only copy the last group's unique number field ~ ~
Below is my preopencard script
PS: tArray is fetching my json object
Code: Select all
put 0 into myVar
put 1 into myID
put 1 into myID1
put 156 into myPosition1
put 184 into MyPosition2
repeat until tArray["users"][myID1]["email"] is empty
add 1 to myVar
add 1 to myID
add 1 to myID1
add 0 to myPosition1
add 164 to myPosition2
if tArray["users"][myID1]["email"] is not empty then
copy group "usersbox"
paste group
move group "usersbox" to myPosition1 , myPosition2 in timing second
put tArray["users"][myID]["idnumber"] into field "idnumber"
put tArray["users"][myID]["fullname"] into field "name"
put tArray["users"][myID]["email"] into field "email"
put tArray["users"][myID]["role"]["rolename"] into field "rolename"
end if
end repeat
PS: I had tried to use your code but it only copy the last group's unique number field ~ ~
Re: Select Group
Hi jwtea,
just change these lines:
Just to be sure, you are NOT trying to fill the fields of the just created group with the next lines?
That will not work of course.
Best
Klaus
just change these lines:
Code: Select all
...
if tArray["users"][myID1]["email"] is not empty then
## copy group "usersbox"
## paste group
clone group "usersbox"
set the name of IT to ("userbox" && myVar)
move group ("usersbox" && myVar) to myPosition1 , myPosition2 in timing second
...
That will not work of course.
Code: Select all
...
put tArray["users"][myID]["idnumber"] into field "idnumber"
put tArray["users"][myID]["fullname"] into field "name"
put tArray["users"][myID]["email"] into field "email"
put tArray["users"][myID]["role"]["rolename"] into field "rolename"
...
Klaus
Re: Select Group
Hello Klaus , thanks for your help! Now my group got each and special unique name.
But i still can't get this to work after typing the code provided by Craig. Any idea why??
But i still can't get this to work after typing the code provided by Craig. Any idea why??
Code: Select all
on mouseUp
put word 2 of the short name of the target into tNumber
put field "uniqueNumberField" && tNumber into field "holding field"
end mouseUp
dunbarx wrote: ↑Fri May 04, 2018 4:38 amBy the way,
let's say i got 10 groups right and inside each group got a unique number field and a widget.
So if i click on the 1st group widget, the unique number field value inside the 1st group will be put into a
field call holding field.
And if i click on the 3rd group widget, the unique number field value inside the 3rd group will be put into the same field call holding field.
Can i know what the code for the above function??