radio button behaviour

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
chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

radio button behaviour

Post by chris25 » Sat Oct 26, 2013 4:40 pm

I set radioButtonBehaviour to false (6 in a group) then add code instructing that only two at one time can be selected: (I have done it with numbers) ...if number of chars in Numb = 2 then ....

How do I use this same concept with buttons and checkboxes?

tjm167us
Posts: 50
Joined: Sat Dec 03, 2011 8:27 pm

Re: radio button behaviour

Post by tjm167us » Sat Oct 26, 2013 5:11 pm

Chris,
Some code of what you did would be helpful (to see exactly what you want to accomplish with just buttons and checkboxes), but sans that:

For determining whether a checkbox is checked, you can use the following phrase:

Code: Select all

the hilite of button "theButton"
This will return true if it is checked, and false otherwise. With this ability, it is a matter of simply keeping track of which checkboxes are highlighted, and which aren't. It would also probably be convenient to have a global variable that keeps track of the number of the checkboxes that are selected (if your controls are not grouped), or a local script variable that serves the same purpose (if your controls are grouped). In this case, I would definitely recommend grouping.

The radioButtonBehavior option is merely a convenience provided to you by the LiveCode folks. Having standalone checkboxes that you must create logic for is the equivalent of having a set of radio buttons, where you elect to set the radioButtonBehavior to false.

How you want to "allow" or "disallow" a user from selecting a third checkbox was not specified in your original post, but is easy to do to using the enabled or visible properties of controls (depending on the look and overall behavior you want).

Code: Select all

set the enabled of button "theButton" to {true|false}//Choose either true or false in your code, omitting the {}
or

Code: Select all

set the visible of button "theButton" to {true|false}
If you do implement the logic in a group (as I recommend), and there is a need to differentiate between which checkboxes are selected, I would use the following code:

Code: Select all

on mouseUp
put the short name of the target into theTarget
switch theTarget
case "button1"
--code here
break
case "button2"
--code here
break
--etc.
end switch
end mouseUp
If you only care about the number of checkboxes that are selected, then in your group handler:

Code: Select all

sNumberChecked = 0

on mouseUp
--add code to count the number of checkboxes whose hilite is true here. Set sNumberChecked accordingly
end mouseUp
With the information given, I'm unsure how or why you would use buttons instead of checkboxes or radio buttons. Some more information will allow me to help you more.

Tom

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

Re: radio button behaviour

Post by Klaus » Sat Oct 26, 2013 6:22 pm

Hi Chris,
chris25 wrote:...How do I use this same concept with buttons and checkboxes?
just like you would do in "real life" with a piece of paper and a pencil,
count all hilited buttons and then act accordingly :)

Add this script to the group with your buttons, of course the buttons need to be set to autohilite = FALSE!

Code: Select all

## Or whatever you like:
constant maxHilites = 2

on mouseUp
  ## UN-hiliting is always allowed
  if the hilite of the target = TRUE then
    set the hilite of the target to FALSE
    exit mouseup
  end if
  
  ## I use this little function below to see if the button is allowed to hilite:
  set the hilite of the target to check4hilite()
end mouseUp

## No witchcraft, just count all hilited buttons :-)
function check4hilite
  put 0 into tCounter
  repeat with i = 1 to the num of buttons of me
    if the hilite of btn i of me = TRUE then
      add 1 to tCounter
    end if
  end repeat
  ## I just love Monsieur Boole :-)
  return (tCounter < maxHilites)
end check4hilite
Best

Klaus

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: radio button behaviour

Post by chris25 » Sat Oct 26, 2013 7:00 pm

card three of three.png
card two of three.png
card one of three.png
Both Tom and Klaus, thankyou for taking the time to reply. I have plenty there to get on with and dissect. By way of clarification I have uploaded four screen shots. I am just trying to translate so much theoretical information now into practise, to try and build a visul framework for the theory that I have learned so I devised a couple of set-ups just to get myself actually doing something rather than just repeating exercises which can be counter-productive to understanding how it all fits together.

So the first three cards are how the user would navigate through a series of choices. The last card was an alternative method so I can learn variation in coding.(Sorry , this last card is not allowed to be uploaded I imagine, it was one with checkboxes on it where the user was allowed to click two boxes (the print size and the resolution before being taken to the final answer) I am particularly wanting to be able to learn by using global variables, scope local variables and temporary variables. I can define these, I have answered the questions correctly, I have done the exercises and got my PHD :) YET, I now need to put it together from my own imagination - and the course does not really prepare you for that I'm afraid, so now I am stuck with variables swimming around my head and trying to stick them on paper in a real situation.

Hope this clarifies my first post.

Thankyou.

tjm167us
Posts: 50
Joined: Sat Dec 03, 2011 8:27 pm

Re: radio button behaviour

Post by tjm167us » Sat Oct 26, 2013 7:09 pm

Experimenting is always the best way to gain experience.
Might I also suggest, as a way of getting ideas and knowing how things "should be" written, to look at some applications that you use daily that you find easy to use. Invariably, if you learn how to mimic these, you too will create applications others find useful!

Keep it up,
Tom

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: radio button behaviour

Post by chris25 » Sat Oct 26, 2013 8:01 pm

Thanks Tom, and point taken.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: radio button behaviour

Post by jacque » Sun Oct 27, 2013 7:47 pm

As an addendum: radio buttons are universally recognized in all operating systems as allowing a single choice among a group of choices. Selecting one deselects the others, which is the default behavior of LiveCode radio buttons.

Checkboxes are universally considered multiple-choice options, and any number can be selected.

For what you want, I'd use checkbox buttons.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply