Radio buttons to show/hide group
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Radio buttons to show/hide group
Hi
I have a group of radio buttons and I have a group of data for each button.
When one button is pressed I want to show it's data group and hide the previous button's group of data.
The showing part is no problem, it's the hiding I can't figure out.
Can someone please point me in the right direction?
Thanks,
Kev
I have a group of radio buttons and I have a group of data for each button.
When one button is pressed I want to show it's data group and hide the previous button's group of data.
The showing part is no problem, it's the hiding I can't figure out.
Can someone please point me in the right direction?
Thanks,
Kev
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Radio buttons to show/hide group
Hi Kevtor and welcome to the forum!
How about something like the following code in the script of your group containing your option buttons?
Dave
PS: I edited my answer to make it more specific to your case - hope it helps...
How about something like the following code in the script of your group containing your option buttons?
Code: Select all
on mouseUp
switch
case the hilite of btn 1 of me
show grp "Data1"
hide grp "Data2"
hide grp "Data3"
break
case the hilite of btn 2 of me
hide grp "Data1"
show grp "Data2"
hide grp "Data3"
break
case the hilite of btn 3 of me
hide grp "Data1"
hide grp "Data2"
show grp "Data3"
break
end switch
end mouseup
PS: I edited my answer to make it more specific to your case - hope it helps...
"...this is not the code you are looking for..."
Re: Radio buttons to show/hide group
Thanks Dave,
Some cutting and pasting, switching shows and hides, changing of group names and it worked like a charm.
Thanks
Kev
Some cutting and pasting, switching shows and hides, changing of group names and it worked like a charm.
Thanks
Kev
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Radio buttons to show/hide group
Good 
Of course "there must be 50 ways" to show/hide your groups with LiveCode and others may chime in with better approaches...

Of course "there must be 50 ways" to show/hide your groups with LiveCode and others may chime in with better approaches...
"...this is not the code you are looking for..."
Re: Radio buttons to show/hide group
Dave.
If the OP has locally explicit show/hide needs, then your approach, essentially a "look-up" table tailored for each case instance, is probably the best.
There is a compulsion among some (like me) to try to condense these sorts of tasks with, say, repeat loops and ordered object references (like "group1", "group2", etc), but often a brute force method is simplest, and easiest to maintain.
Craig Newman
If the OP has locally explicit show/hide needs, then your approach, essentially a "look-up" table tailored for each case instance, is probably the best.
There is a compulsion among some (like me) to try to condense these sorts of tasks with, say, repeat loops and ordered object references (like "group1", "group2", etc), but often a brute force method is simplest, and easiest to maintain.
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Radio buttons to show/hide group
Craig
I will admit to considerable 'brute force' tendencies in my code but am not without SOME refactoring tendencies
You recently took part in this conversation: http://runtime-revolution.278305.n4.nab ... l#a4684359 where Geoff wrote my favourite coding aphorism of recent times:
Dave
I will admit to considerable 'brute force' tendencies in my code but am not without SOME refactoring tendencies

You recently took part in this conversation: http://runtime-revolution.278305.n4.nab ... l#a4684359 where Geoff wrote my favourite coding aphorism of recent times:
Kind regardsPremature optimization is the root of <some> evil...
Dave
"...this is not the code you are looking for..."
Re: Radio buttons to show/hide group
I generally use a repeat loop and just hide everything. After the loop completes I show the object I want. This works for any number of objects, uses a small amount of code (one line inside the loop) and doesn't require any customization. You can add new objects to the group later and it still works without changes.
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: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Radio buttons to show/hide group
Thanks for the replies everyone.
I tried to do a repeat but I was trying to save names to variables and couldn't get it to work.
It works for now using switch/case so I can move on to other parts of the project but I intend to come back to it and try Jaque's method for the heck of it.
With 14 buttons the script ended up quit wordy, heh.
Thanks,
Kev
I tried to do a repeat but I was trying to save names to variables and couldn't get it to work.
It works for now using switch/case so I can move on to other parts of the project but I intend to come back to it and try Jaque's method for the heck of it.
With 14 buttons the script ended up quit wordy, heh.
Thanks,
Kev
Re: Radio buttons to show/hide group
I was playing with this little bit and came up with:
see the attached stack
Maybe that's what Jacque meant?
Code: Select all
on mouseUp
repeat with x = 2 to the number of grps of this cd -- start with grp 2 since grp 1 is the radiobuttons
hide grp x
end repeat
put label of target into tNr; show grp (tNr +1)
end mouseUp
Maybe that's what Jacque meant?
- Attachments
-
- show-hide groups.zip
- (1.11 KiB) Downloaded 248 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit
Re: Radio buttons to show/hide group
Hi.
Exactly
What I mentioned) earlier in the thread was more like this. Say you have groups named "grp1, grp2,grp3, otherGrp1, otherGrp2, otherGrp3, etc. I mentioned a loop that referenced some property of those groups, in this case, their names:
See? This will hide only those groups where their names resolve to the "otherGrp", er group, and hide them. More important, do you see how the simple concatenation works?
Craig
Exactly
What I mentioned) earlier in the thread was more like this. Say you have groups named "grp1, grp2,grp3, otherGrp1, otherGrp2, otherGrp3, etc. I mentioned a loop that referenced some property of those groups, in this case, their names:
Code: Select all
on mouseUp
repeat with y = 1 to the number of groups
hide grp "otherGrp" & y
end repeat
end mouseUp
Craig
Re: Radio buttons to show/hide group
Yes, that's what I meant.
I'd recommend not using semicolons to concatenate two lines of code. One person in the forums does that but it's nonstandard and is likely to cause more work for the parser. But mainly it makes your code harder to read.
Another pet peeve of mine is the omission of the word "rhe" for properties. This has taken off here in the forums after a few people began writing scripts that way. It forces the parser to do much more work to determine whether the word is a variable or a property name.
I'd recommend not using semicolons to concatenate two lines of code. One person in the forums does that but it's nonstandard and is likely to cause more work for the parser. But mainly it makes your code harder to read.
Another pet peeve of mine is the omission of the word "rhe" for properties. This has taken off here in the forums after a few people began writing scripts that way. It forces the parser to do much more work to determine whether the word is a variable or a property name.
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: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: Radio buttons to show/hide group
Jacque - that's interesting about the cost of dropping the "the" in properties - the dictionary doesn't mention this
Any other 'bad style' practices that lead to slow-downs spring to mind?The the keyword is optional before the names of properties, but it is good style to include it.
"...this is not the code you are looking for..."
Re: Radio buttons to show/hide group
What Jacque meant, and she too much of a lady to say it, was this:
It is TERRIBLE to append multiple lines of code that way. I am perplexed why the feature is supported at all. I think it was proposed by liberal Hollywood A-list actors.
Lines are cheap. Readability is not.
Craig
It is TERRIBLE to append multiple lines of code that way. I am perplexed why the feature is supported at all. I think it was proposed by liberal Hollywood A-list actors.
Lines are cheap. Readability is not.
Craig
Re: Radio buttons to show/hide group
Dave, good catch. I wasn't aware that the dictionary said that. That may explain why so many have adopted the style.
Perhaps it isn't as awful as I thought and my reaction is just me being a purist. But logically I think it would produce the same type of slowdown as unquoted literals where the engine has to work out what you meant. If I weren't so lazy I'd do a timing test.
Perhaps it isn't as awful as I thought and my reaction is just me being a purist. But logically I think it would produce the same type of slowdown as unquoted literals where the engine has to work out what you meant. If I weren't so lazy I'd do a timing test.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com