Storing menu option data

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
tasdvl9
Posts: 94
Joined: Fri Dec 06, 2013 3:55 am

Storing menu option data

Post by tasdvl9 » Sun Feb 16, 2014 10:15 pm

Hello,

I Implemented a Combobox(menu option) inside my code:

on menuPick pItemName
switch pItemName
case "Yes"
answer "You selected Yes" with "Okay"
break
case "No"
answer "You selected No" with "Okay"
break
case "NA"
answer "You selected NA" with "Okay"
break
end switch
end menuPick

How do I store pItemName so that I can use it in my array like this?:
put text of field "pItemName" into myData["pItemName"]

I know the above is wrong but this is similar to what I need to do.
I just need to store my answer so that I can use it later.

Thanks!

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

Re: Storing menu option data

Post by dunbarx » Sun Feb 16, 2014 10:49 pm

Hi.

What makes you think the the line of code is wrong?

Anyway, if you want to store it, set a custom property:

set the yourPropertyName of btn "yourButton" to pItemName.

That can be executed in the option button script. Note that since pItemName is a variable, it must not be quoted.

Craig

tasdvl9
Posts: 94
Joined: Fri Dec 06, 2013 3:55 am

Re: Storing menu option data

Post by tasdvl9 » Sun Feb 16, 2014 11:01 pm

Hi, Thanks for the response.

Still having a bit of an issue.

pItemName stores my selection. In this case 'Yes.'
I'm looking to store the selection into a variable so I can use it later.

I'm used to doing this with a text field like so:
put htmltext of field "company_name" into myData["company_name"]

but not sure how to do this with a combobox/menu option.

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

Re: Storing menu option data

Post by Klaus » Sun Feb 16, 2014 11:17 pm

Hi tasdvl9,

what about something like this, please note my short script, which is pure lazyness :D

Code: Select all

on menuPick pItemName
  global myData ##?
  answer ("You selected" && pItemName) with "Okay"
  put pItemName into myData["user_choice"]
end menuPick
Best

Klaus

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

Re: Storing menu option data

Post by dunbarx » Sun Feb 16, 2014 11:37 pm

Hi.

When you say "store for later", I take this to mean really later. A custom property is stored with the stack file, like text in a field. So if you had your original handler:

Code: Select all

on menuPick pItemName
switch pItemName
case "Yes" 
set the selectionPicked of this button to pItemName --THIS IS WHERE THE DATA IS STORED IN A CUSTOM PROPERTY
answer "You selected Yes" with "Okay"
break 
case "No" 
answer "You selected No" with "Okay"
break 
case "NA" 
answer "You selected NA" with "Okay"
break 
end switch
end menuPick
At any time you need to, in any script or by hand, you can:

answer the selectionPicked of this button

Or am I missing this?

Craig

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Storing menu option data

Post by Simon » Sun Feb 16, 2014 11:43 pm

Wow Craig!
You just set a light-bulb off in my head!

One doesn't have to pre-define a custom property like a global must be. It does add "of this stack" or whatever. I may just give up on using globals.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

tasdvl9
Posts: 94
Joined: Fri Dec 06, 2013 3:55 am

Re: Storing menu option data

Post by tasdvl9 » Mon Feb 17, 2014 12:20 am

Outstanding, Everyone!
Thanks! That's exactly what I was looking for. I appreciate the responses.

Quick question..
Is there a way to get the current selection of the menu option?
When my card is invoked I'd like to be able to retrieve the current answer(yes/no) in the menu option.

In C++ you can do something like GetCurrentSelection->handleTocontrol
So I was wondering if you can do something similar in Livecode.

Forgive my reference to C++. I just wanted to further illustrate what I am asking :)

Thanks!

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

Re: Storing menu option data

Post by dunbarx » Mon Feb 17, 2014 12:22 am

Simon.

Properties (and custom properties) are sort of like "ordinary" variables that way, though they must be married to an object. They are "declared" and populated on the fly. So easy...

Craig

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

Re: Storing menu option data

Post by dunbarx » Mon Feb 17, 2014 12:23 am

Is there a way to get the current selection of the menu option?
When my card is invoked I'd like to be able to retrieve the current answer(yes/no) in the menu option.
Read up on the "menuHistory" in the dictionary.

Craig

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

Re: Storing menu option data

Post by Klaus » Mon Feb 17, 2014 12:54 am

Hi tasdvl9,
tasdvl9 wrote:Is there a way to get the current selection of the menu option?
yes:
...
put the LABEL of btn "your option menu button here..." into tCurrentSelection
...
:D


Best

Klaus

tasdvl9
Posts: 94
Joined: Fri Dec 06, 2013 3:55 am

Re: Storing menu option data

Post by tasdvl9 » Mon Feb 17, 2014 1:19 am

Thanks, guys! :)
Works like a charm.

Post Reply