[SOLVED] How do I put the chosen item of a combo box or list box into a variable?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
karmacomposer
Posts: 361
Joined: Wed Apr 27, 2011 2:12 pm

[SOLVED] How do I put the chosen item of a combo box or list box into a variable?

Post by karmacomposer » Fri Jul 20, 2018 1:55 am

I have a combo box (drop down list) with US states and I need to put that into a variable.

In another button, I need to do something with that same variable.

I did the following:

Code: Select all

on menuPick pChosenItem, pPreviousTab
   global varState
   put pChosenItem into varState
   --answer varState with "ok"
end menuPick
That does seem to work (the commented out answer box would show me the correct picked state), but when I try to do something with that same variable when pressing a button, the answer box just shows the word varState, not the contents of the variable varState.

I tried:

Code: Select all

put the text of varState into varStateNew
that did not work and threw an error.

How can I get the value of varState into another control's script?

Mike
Last edited by karmacomposer on Fri Jul 20, 2018 5:40 am, edited 1 time in total.

ClipArtGuy
Posts: 253
Joined: Wed Aug 19, 2015 4:29 pm

Re: How do I put the chosen item of a combo box or list box into a variable?

Post by ClipArtGuy » Fri Jul 20, 2018 4:28 am

This script is working as-is here. Make sure you've declared the global in the script you are using it in. Globals need to be declared in every script that uses them. if undeclared, it will be created as an empty local variable on the fly.

ClipArtGuy
Posts: 253
Joined: Wed Aug 19, 2015 4:29 pm

Re: How do I put the chosen item of a combo box or list box into a variable?

Post by ClipArtGuy » Fri Jul 20, 2018 4:38 am

I think one thing that is messing you up, is using "the text". From this example, you used this :

Code: Select all

put the text of varState into varStateNew
but what you'd want is this:

Code: Select all

put varState into varStateNew
Same thing for the auto populate example. You used :

Code: Select all

 set the text of field "fldDateAllottStart" to varNowDate
when what you should use is:

Code: Select all

put varNowDate into "fldDateAllottStart" 

karmacomposer
Posts: 361
Joined: Wed Apr 27, 2011 2:12 pm

Re: How do I put the chosen item of a combo box or list box into a variable?

Post by karmacomposer » Fri Jul 20, 2018 4:42 am

OK, I got it working, but one last problem.

I would like to write the result back to the control.

I wrote this:

Code: Select all

set the text of field "fldState" to it
However, it's a combobox (dropdown list) - how do I write the variable varState back to the control so it shows? Do I use the label command to change the label of cbState?

How would I auto-populate the list back with the 50 states - because when you change the label of the dropdown, you empty the list of states.

Mike

ClipArtGuy
Posts: 253
Joined: Wed Aug 19, 2015 4:29 pm

Re: How do I put the chosen item of a combo box or list box into a variable?

Post by ClipArtGuy » Fri Jul 20, 2018 4:44 am

again, "the text" is what is wrong here. This is what you want:

Code: Select all

put it into fld "fldState"
Although, here, the combo box shows the choice that has been selected without any need to write back to the control.

karmacomposer
Posts: 361
Joined: Wed Apr 27, 2011 2:12 pm

Re: How do I put the chosen item of a combo box or list box into a variable?

Post by karmacomposer » Fri Jul 20, 2018 4:48 am

That threw an error in the compiler.

The control is a drop down list - not a field.

In fact, I was wrong - the field name is cbState

Still throws an error when I changed it to the correct name.

Mike

ClipArtGuy
Posts: 253
Joined: Wed Aug 19, 2015 4:29 pm

Re: How do I put the chosen item of a combo box or list box into a variable?

Post by ClipArtGuy » Fri Jul 20, 2018 4:54 am

I was just pointing out that using "set the text" when you should be using "put" is going to cause you headaches every time.

As far as the dropdown menu, you need to change the label:

Code: Select all

set the label of btn "myDropdownMenu" to "myNewLabel"

karmacomposer
Posts: 361
Joined: Wed Apr 27, 2011 2:12 pm

Re: How do I put the chosen item of a combo box or list box into a variable?

Post by karmacomposer » Fri Jul 20, 2018 5:04 am

Thank you. That did it!

Before I mark this solved, is there a way to auto find a state in the list if the user types a set of letters,
for example, without even dropping down the list, I press 'F' and Florida comes up. How would I do this?

Also, does LiveCode have a auto-complete feature such that if you typed something before in a field, it would auto populate with that information?

Thanks.

Mike

ClipArtGuy
Posts: 253
Joined: Wed Aug 19, 2015 4:29 pm

Re: How do I put the chosen item of a combo box or list box into a variable?

Post by ClipArtGuy » Fri Jul 20, 2018 5:06 am

When it comes to autocomplete in your fields and menus, I think you'll need to roll your own. I am sure someone will chime in if that's not correct

Post Reply

Return to “Talking LiveCode”