Page 1 of 1

Storing menu option data

Posted: Sun Feb 16, 2014 10:15 pm
by tasdvl9
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!

Re: Storing menu option data

Posted: Sun Feb 16, 2014 10:49 pm
by dunbarx
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

Re: Storing menu option data

Posted: Sun Feb 16, 2014 11:01 pm
by tasdvl9
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.

Re: Storing menu option data

Posted: Sun Feb 16, 2014 11:17 pm
by Klaus
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

Re: Storing menu option data

Posted: Sun Feb 16, 2014 11:37 pm
by dunbarx
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

Re: Storing menu option data

Posted: Sun Feb 16, 2014 11:43 pm
by Simon
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

Re: Storing menu option data

Posted: Mon Feb 17, 2014 12:20 am
by tasdvl9
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!

Re: Storing menu option data

Posted: Mon Feb 17, 2014 12:22 am
by dunbarx
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

Re: Storing menu option data

Posted: Mon Feb 17, 2014 12:23 am
by dunbarx
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

Re: Storing menu option data

Posted: Mon Feb 17, 2014 12:54 am
by Klaus
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

Re: Storing menu option data

Posted: Mon Feb 17, 2014 1:19 am
by tasdvl9
Thanks, guys! :)
Works like a charm.