PopUp to TextLabel?

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
martimer
Posts: 39
Joined: Tue Jun 25, 2013 9:24 pm

PopUp to TextLabel?

Post by martimer » Tue Jan 15, 2019 5:31 am

I am a longtime programmer who has been "out of the game" and am trying to return to the hobby after a long absence. I need a little nudge here.

I am just trying to get restarted with how LC works, I have a lot settled but got stuck on this problem, I am hoping someone can either provide a simple example stack, or walk me through it. Could be a simple one stack example!

How do I get the data/selection from an Option Menu to a text Label Field via a short script? My goal is to eventually use a "centralized script" available from a stack to collect the various pieces of data from several Option Menus and spill the results into a Label Field for display of the calculations. Simple, I just cannot remember/find how to do that.

So, the Option Menu would get a value from its list of options (I understand how to make those custom selections) and pass it to a script that would perform some simple manipulations (I will be using "numerical data", I understand how to convert that from text to the integer equivalent) and then putting the results into a Label Field on the same stack.

Help is appreciated. I used to be able to do this sort of thing in other development environments. I understand methods and handlers and objects, etc. The syntax is a little different here and I am stumbling over remembered data. I thought I would not have this problem, but life is funny that way! To the best of my knowledge LC is the way I will be going in the future, so might as well make the transition! Strictly a hobbyist - my professional developer days are behind me.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: PopUp to TextLabel?

Post by jmburnod » Tue Jan 15, 2019 9:49 am

Hi,
If I understand correctly what you want to do i think "label" is the magic word.
something like that:

Code: Select all

...
   put empty into tAllLabels
   put "mybtnoption1,mybtnoption2" into tAllOptions
   repeat for each item tOneOption in tAllOptions
    put (the value of  the label of btn tOneOption) & cr after tAllLabels
   end repeat
   put tAllLabels
...
I noticed that the value doesn't work with a string that contains a space char.
The value of "choice 1" return an error

Best regards
Jean-Marc
https://alternatic.ch

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: PopUp to TextLabel?

Post by bogs » Tue Jan 15, 2019 12:21 pm

martimer wrote:
Tue Jan 15, 2019 5:31 am
How do I get the data/selection from an Option Menu to a text Label Field via a short script?
Taking you literally, it could be something as simple as this -
Selection_001.png
Option to label...
Mind you, there are only 2 controls there, I didn't name anything, but if your going more than that I would make it more like

Code: Select all

on menuPick pItemName
   put pItemName into field "MySnazzyField"
end menuPick
or, if the labels span cards/stacks you would use the longer

Code: Select all

put pItemName into field "MySnazzyField" of card "myCard" of stack "mystack"
If it is something else, please feel free to write back :D
Image

martimer
Posts: 39
Joined: Tue Jun 25, 2013 9:24 pm

Re: PopUp to TextLabel?

Post by martimer » Thu Jan 17, 2019 11:58 pm

Thanks for the replies. I have managed to injure my left eye and so am not as nimble with the keyboard as I like to be - I am healing and will get back to this as soon as I am able to focus properly! Sorry for radio silence!

(Hey, RunRev, please stop changing my password! Thanks.)

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: PopUp to TextLabel?

Post by bogs » Fri Jan 18, 2019 11:48 am

Hope your eye gets better soon, if possible. We will still be here when your ready to go :wink:
Image

martimer
Posts: 39
Joined: Tue Jun 25, 2013 9:24 pm

Re: PopUp to TextLabel?

Post by martimer » Sat Jan 19, 2019 4:18 am

Thanks for the well-wish. I am able to read large high-contrast text now!

Anyway, I started digging around and have come up with some things that are working and some things that are not.

I have a stack with 4 controls on it - A Choice Menu, a Label Field to display its contents a PopUp Menu and a Label Field2 to display its contents. The following script is in the script for the card itself:

on mouseUp
Set the text of field "Label Field" to the Label of button "ChoiceButton"
Set the text of field "Label Field2" to the Text of button "PopUp Menu"
end mouseUp

The first Set works perfectly.
The second Set just makes Lebel Field2 blank. The PopUp Menu is labeled "Pick One" and the text is:
"1
2
3"

So, my questions:

How do I "capture" the SELECTION of the PopUp Menu? For now I am happy to just put it into the label.

Where can I read about how a PopUp Menu works? I cannot find any discussion of examples in the Beginners Guide OR Users Guide OR Resources OR Dictionary. Is there a guide for the controls?

How are people using the Dictionary? There is no search function that I can find. I cannot locate anything about the UI elements.

Is written documentation dead?

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: PopUp to TextLabel?

Post by bogs » Sat Jan 19, 2019 11:27 am

martimer wrote:
Sat Jan 19, 2019 4:18 am
How are people using the Dictionary? There is no search function that I can find. I cannot locate anything about the UI elements.

Is written documentation dead?
As far as this question goes, the search box is the one highlighted, the guide (which is one of the few things I think actually improved in the newer versions) is located where the arrow is pointing. While I use the dictionary a lot, I use this version of Lc far less.
Dictionary_002.png
Guide to the dictionary...
When I do use it, I tend to use Bernd's "Tiny dictionary" plug in, it can be found in the user share section.
martimer wrote:
Sat Jan 19, 2019 4:18 am
How do I "capture" the SELECTION of the PopUp Menu? For now I am happy to just put it into the label.
Well, to 'capture' it, you would do something like I did in the first example, although there are many many other ways to do it.

Somethings though never (seem to) change though, and manipulating text is one of those things Lc really makes pretty easy. The question I have at this point is, did you try either suggestion by Jean-Marc or myself? His suggestion works based on the label of the button, mine works by which menu item you selected, and while his is more readily located just about anywhere, either can be made to work that way (my handler is directly in the menu buttons script).

In any case, we'll move on to your main question, the results you got -

Code: Select all

on mouseUp
Set the text of field "Label Field" to the Label of button "ChoiceButton"
Set the text of field "Label Field2" to the Text of button "PopUp Menu"
end mouseUp
Now, look at this picture...
Selection_003.png
Pointing at you...
What is going on here is that the button your working with has both a label and text section. The label is what is showing at the end of making the selection. The text is the list of choices. You used the 'set' command for this (I would have opted for 'put' myself), but either road you wind up with exactly the same result. Set your stack up like the above and try it yourself :)
Image

martimer
Posts: 39
Joined: Tue Jun 25, 2013 9:24 pm

Re: PopUp to TextLabel?

Post by martimer » Sat Jan 19, 2019 1:07 pm

Yes I have "explored" the lessons posted above, all very helpful and I thank you all for that. I think I have the Option Menu figured out.

My latest questions are about the PopUp Menu - I should not have drifted the conversation. Used on what I have seen, I think the Option Menu is what I am looking for anyway.

I was looking at the "Guide" part of the Dictionary. Switching to the API part brought out the search feature! Lots of new toys and paradigms...

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: PopUp to TextLabel?

Post by bogs » Sat Jan 19, 2019 2:53 pm

martimer wrote:
Sat Jan 19, 2019 1:07 pm
I should not have drifted the conversation
That is ok to do, often it will drift to like things, just mention what it is drifting too and everythings fine :wink:

Ah, a pop up menu! It is not much different than the option menu, but there is one important distinction and that is that the 'label' of it will not change unless you do so programmatically, i.e.
Selection_007.png
New buttons....
Image

martimer
Posts: 39
Joined: Tue Jun 25, 2013 9:24 pm

Re: PopUp to TextLabel?

Post by martimer » Sat Jan 19, 2019 6:05 pm

Yeah, a bit different. I decided to go with the Option thing rather than the PupUp, same result just a different way of displaying things.

Thanks.

Just out of lingering curiosity, how do I get the selection of a PopUp Menu?

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: PopUp to TextLabel?

Post by bogs » Sat Jan 19, 2019 6:22 pm

Same as you see in the pic or the first block of code

Code: Select all

on menuPick pItemName
// pItemName is the selection in this handler
   put pItemName into field "MySnazzyField"
end menuPick
Image

martimer
Posts: 39
Joined: Tue Jun 25, 2013 9:24 pm

Re: PopUp to TextLabel?

Post by martimer » Sat Jan 19, 2019 6:57 pm

Selection. Got it! Thanks again.

All is well, now on to data grids...

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: PopUp to TextLabel?

Post by bogs » Sat Jan 19, 2019 9:36 pm

martimer wrote:
Sat Jan 19, 2019 6:57 pm
now on to data grids...
Make sure you go through the guide section on it 2, or even 9 times maybe :P
Image

martimer
Posts: 39
Joined: Tue Jun 25, 2013 9:24 pm

Re: PopUp to TextLabel?

Post by martimer » Sun Jan 20, 2019 2:34 am

Only up to 6 and I know how to set one up and get data from the selected row...

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”