Option button

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
r_houdek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 12
Joined: Wed Feb 23, 2011 1:35 am

Option button

Post by r_houdek » Mon Apr 28, 2014 4:35 pm

I have an option button with dozens of options. How can I programmatically change the default option?

For example - the options include all states:

AL
AK
AR
AZ
CA
CO
CT


Based on some criteria I may want the default to be "CA" instead of "AL" - I can't seem to find the right syntax.

Thanks!

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Option button

Post by Klaus » Mon Apr 28, 2014 4:51 pm

Hi r_houdek,

you can set the label of your option button:
...
set the label of btn "your option here" to "CA"
...


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Option button

Post by dunbarx » Mon Apr 28, 2014 9:32 pm

Hi.
Klaus has given you a method. This gives the user a physical label.

Another way, and I think of this as a more "natural" method, is to set the "menuHistory" of the button. This actually "selects" the line that contains that data. This, to me, is far more robust for several reasons.

Try this. On a blank card. make an option button, It will be pre-loaded with three lines, "choice 1, choice 2 and choice3". Now make another ordinary button, and put this into its script:

Code: Select all

on mouseUp
   set the label of btn 1 to any item of "choice 1,choice 2,choice 3"
   answer  the menuhistory of btn 1
end mouseUp
Now manually select line 3 ("choice 3") of the option button. This actually selects that third line, and shows "choice 3", which is the contents of the third line.

Now click on the ordinary button. You will see, after several tries, that the "label" of the option menu changes, but that the menuHistory never does. This is because we never "selected" a different line, we only changed the label of the button. Why does this matter? Well, two different properties are at play here, but only one works the option menu functionality directly. If you really start to use that option menu, where you select a line and then use a "menuPick" handler to do real work, or if you want the "label" of the button to reflect the actual line selected (and shown) in that button, then you have to deal with those properties. Remember, the label property "floats" above the actual selected line and trumps the display of the contents of that line. I do not see a case where the label should be set with such an object at all, if you ever want to use it for anything useful. But in that case, you do not need an option menu. Any button will do, as the label property is ubiquitous.

Is this clear? Do experiment for a bit until you understand the distinction.

Klaus, would you not agree?

Craig

r_houdek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 12
Joined: Wed Feb 23, 2011 1:35 am

Re: Option button

Post by r_houdek » Mon Apr 28, 2014 11:43 pm

Great advice.

Thank you both!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9388
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Option button

Post by richmond62 » Tue Apr 29, 2014 5:33 pm

I've NEVER used an Option Button in my 12 years of working with Livecoding: but thought it probably wouldn't
be that difficult.

So, I made a new stack with a new option button bang in the middle of it.

In the prefs palette of the option button I put this list:

CA
AL
AK
AR
AZ
CO
CT

notice the difference from yours (goofy or what?).

AND; perhaps unsurprisingly, that means that 'CA' is default.
LC_gadfly.png

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Option button

Post by Klaus » Tue Apr 29, 2014 5:42 pm

What a cunning plan, Baldrick! :D

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Option button

Post by dunbarx » Tue Apr 29, 2014 6:10 pm

Richmond.

I am dense. What did you mean by your last post? A new option menu will by default have its menuHistory set to 1, which is the first line in its contents.

Craig

EDIT:

Oh, maybe you simply forced the default to be the actual line that was of interest? Hmm. That will change as soon as you select any other line. You then have to reset the menuHistory back to 1. So if you don't care about alphabetized listings, I guess you could do this. But this is a kluge. Better to simply use the tools available in a straightforward manner.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”