referencing item in dropdown menu form another handler

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
chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

referencing item in dropdown menu form another handler

Post by chris25 » Mon Nov 04, 2013 1:33 pm

I would like have the final calculation button code be able to reference a particular combination of items in two drop down menus. For example: the calculate button will have a conditional clause/code where if it is this variable do this if it is that variable do that - like this - if the user picks grams in first menu and ounces in second menu this combination will go into a myVaribiable1; if user picks the ounces in the first and grams in the second then this combination goes into myVariable2. These two conditions are governed NOT by the combination itself, but by the fact that 3 of the combinations need to be divided, and 7 need to be multiplied.

Question: My rudimentary thinking is something like this: (All this goes into the final calculate button) The actual pull down menu scripts will not need to be changed because they have the mathematics coded and contained within their variables and all set to go here.

if pulldownmenu01 contains item grams and pulldownmenu02 contains item ounces then
put this combination into myVariable01

Or should I declare a variable for example:

field pdm01 contains ounces,kilograms and fld pdm02 contains grams,lbs (uk), = gDiv

If there are any written references to this sort of thing then gladly please, let me read them, but I had trouble finding anything where people were referencing the items within the dropdown menu.

Thankyou
chris

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

Re: referencing item in dropdown menu form another handler

Post by Klaus » Mon Nov 04, 2013 2:10 pm

Hi Chris,

you want to check -> the LABEL of btn "your option menu here..."


Best

Klaus

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: referencing item in dropdown menu form another handler

Post by chris25 » Mon Nov 04, 2013 2:30 pm

Such a straightforward simple answer Thankyou Klaus - and there I was reading about "integer logic implementation for drop down menu variability environmental deployment" :lol:

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: referencing item in dropdown menu form another handler

Post by chris25 » Mon Nov 04, 2013 3:28 pm

Where is the missing "then", I have counted the 'ifs', and the 'thens' match up?

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

Re: referencing item in dropdown menu form another handler

Post by Klaus » Mon Nov 04, 2013 6:22 pm

chris25 wrote:Such a straightforward simple answer
And it is even correct syntax, so please USE it, and put all STRINGS in QUOTES!
-> if the label OF BUTTON "pdm01" = "lbs(uk)" ...

Missing THEN:
I have no idea, that's why I avoid nested if clauses whereer possile! :D
Use this form:
on mouseup

Code: Select all

  if the label OF BUTTON "pdm01" = "lbs(uk)" AND the label OF BUTTON "pdm02" = "ounces" THEN
     ## do this or that...
     EXIT moseup
  end if

  ## Now youcan check with ONE if then else:
  if .... THEN
   # do that
  ELSE
  ## do somehting else
  end if
end mouseup
Or use a SWITCH structure:

Code: Select all

...
switch 
case the label OF BUTTON "pdm01" = "lbs(uk)" AND the label OF BUTTON "pdm02" = "ounces"
  do something
break
case the label OF BUTTON "pdm01" = "kilogram)" AND the label OF BUTTON "pdm02" = "lbs(uk)"
  ## ...
break
case the label OF BUTTON "pdm01" = "another value" AND the label OF BUTTON "pdm02" = "yet another value"
  ## ...
break
end switch
...
Best

Klaus

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: referencing item in dropdown menu form another handler

Post by chris25 » Mon Nov 04, 2013 6:38 pm

Hi Klaus, funny I was for the first time just experimenting with the switch structure, so glad you posted that, I was hitting all sorts of issues....Thanks.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: referencing item in dropdown menu form another handler

Post by jacque » Mon Nov 04, 2013 8:12 pm

I suspect the "missing then" is a spurious error because the syntax for "label" was wrong. The engine couldn't quite pinpoint what the problem was, so it reports the closest error match. Sometimes that happens. Another common one is that the line is missing a comma. It's almost never that, but it does clue you to the fact that there's a syntax error somewhere in the line.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: referencing item in dropdown menu form another handler

Post by chris25 » Mon Nov 04, 2013 8:50 pm

Hallo Jacque, yes, I often find it difficult to get the syntax right after looking in the dictionary, it's hard to know how to interpret the various brackets and italics and so forth, there is no shall we say 'how to use this dictionary' page. the label and the switch and the case were just three elements where I was having a spot of bother trying to figure out the syntax from the dictionary. I usually try to find other peoples' scripts as examples but could not find a script this time.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: referencing item in dropdown menu form another handler

Post by jacque » Mon Nov 04, 2013 8:57 pm

Yes, it took me a while to figure out the syntax format at first too. The easiest thing it to just look at the examples section in each entry. Those are always present.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: referencing item in dropdown menu form another handler

Post by chris25 » Mon Nov 04, 2013 11:59 pm

Yes but the examples can be just as cryptic as well on ocaisions.

Post Reply