PopUp Menu perceived anomaly

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
CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

PopUp Menu perceived anomaly

Post by CAsba » Thu Mar 16, 2023 11:16 am

Hi,
I'm using the following code:

Code: Select all

on menuPick pitemname
   
   switch pitemname
      case "The product is a consumable, normally sold in a shop, no invoice raised, for example, a packet of biscuits." #titled fld "fieldboxtitle" of cd "template1"
         put "consu" into field "type"
         send "mouseup" to btn "afterbiscuits"
         exit menupick 
         break
         exit menupick
   end switch
but the btn 'afterbiscuits' is not invoked. Instead the code carries on - neither exit statement is invoked.
Any ideas why this is so ?

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

Re: PopUp Menu perceived anomaly

Post by Klaus » Thu Mar 16, 2023 11:42 am

Could you please post the complete "menupick" handler?

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: PopUp Menu perceived anomaly

Post by CAsba » Thu Mar 16, 2023 12:08 pm

Hi Klaus, here it is..

Code: Select all

on menuPick pitemname   
   switch pitemname
      case "The product is a consumable, normally sold in a shop, no invoice raised, for example, a packet of biscuits."
         put "consu" into field "type"
         send "mouseup" to btn "afterbiscuits"
         exit menupick 
         break
         exit menupick
   end switch
   switch pitemname
      case "It is a service, for example, repairing computers. Any parts used would be invoiced seperately."
         put "servi" into field "type"         
         break
   end switch
   switch pitemname
      case "It is a product manufactured by the business, for example, an upholstered headboard."
         put "manuf" into field "type"
         break
   end switch
   switch pitemname
      case "It is a component of a manufactured product, for example, a roll of fabric."         
         put "compo" into field "type"
         break
   end switch
   switch pitemname
      case "It is a consumer durable, for example, a sofa, or a car, where an invoice would normally be raised."         
         put "durab" into field "type"
         break
   end switch
   
   answer "The type chosen may edited after the product entry is completed, if required"titled fld "fieldboxtitle" of cd "template1"
   hide button "PopUp Menu1"
   hide button "PopUp Menu3"
   set the loc of btn "popup menu1" to "614,538"
   set the loc of btn "popup menu2" to "614,538"
   set the loc of btn "popup menu3" to "614,538"
   show button "PopUp Menu2"
   answer "Now select a further characteristic of the product."titled fld "fieldboxtitle" of cd "template1"
  end menupick pitemname

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

Re: PopUp Menu perceived anomaly

Post by Klaus » Thu Mar 16, 2023 12:28 pm

Thanks, looks like a syntax issue!

You need to use only one SWITCH for all CASEs, the "break" will leave the switch automatically. Try this:

Code: Select all

on menuPick pitemname   
   switch pitemname
      case "The product is a consumable, normally sold in a shop, no invoice raised, for example, a packet of biscuits."
         put "consu" into field "type"
         send "mouseup" to btn "afterbiscuits"
         break
      case "It is a service, for example, repairing computers. Any parts used would be invoiced seperately."
         put "servi" into field "type"         
         break
      case "It is a product manufactured by the business, for example, an upholstered headboard."
         put "manuf" into field "type"
         break
      case "It is a component of a manufactured product, for example, a roll of fabric."         
         put "compo" into field "type"
         break
      case "It is a consumer durable, for example, a sofa, or a car, where an invoice would normally be raised."         
         put "durab" into field "type"
         break
   end switch

   ## Better use parens if you use concatenated object names:
   answer "The type chosen may edited after the product entry is completed, if required" titled (fld "fieldboxtitle" of cd "template1")
   hide button "PopUp Menu1"
   hide button "PopUp Menu3"
   set the loc of btn "popup menu1" to "614,538"
   set the loc of btn "popup menu2" to "614,538"
   set the loc of btn "popup menu3" to "614,538"
   show button "PopUp Menu2"
   ## See above
   answer "Now select a further characteristic of the product." titled (fld "fieldboxtitle" of cd "template1")
end menupick pitemname

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: PopUp Menu perceived anomaly

Post by CAsba » Thu Mar 16, 2023 12:47 pm

Thanks, Klaus, I'll try it.

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: PopUp Menu perceived anomaly

Post by CAsba » Thu Mar 16, 2023 1:12 pm

Hi Klaus,
Sorry to report that it is still nopt working. The send mouseup to the button 'afterbiscuits' is not being called.

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

Re: PopUp Menu perceived anomaly

Post by Klaus » Thu Mar 16, 2023 1:42 pm

Do you get any errors or does it just not work?
Is the button on the same card as the popup?

Hint:
If you use a handler more than once, it is always a good idea to "outsource" it to
the card or stack script. Do like this, instead of using a button script like:

Code: Select all

on mouseup
  dothis
  dothat
  andthattoo
end mouseup
and later -> send "mouseup" to button X.

You should put this into the card or stackscript:

Code: Select all

command do_many_things
  dothis
  dothat
  andthattoo
end do_many_things
And then this in the button script:

Code: Select all

on mouseup
  do_many_things
end mouseup
This way you can execute this command later as often as neccessary outside of the button without the need to "send mouseup to ..."

To "debug" your handler, put only this into the button:

Code: Select all

on mouseup
  beep
  ## your regular stuff
  ## and more of that but commented OUT!
end mouseup
And see if THAT works.
If not then there may be something wrong in the message path.

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: PopUp Menu perceived anomaly

Post by CAsba » Thu Mar 16, 2023 2:15 pm

Hi Klaus,
I put in a simpler option ("12") and it called the btn "afterbiscuits"; so, that turned out to be an anomaly between the selection text and the script text, I suppose..

But, the exit instruction was not invoked, the afterbiscuits btn did its thing, but then the popupmenu was reverted to - the code at the bottom was invoked, so I still have a problem getting it to leave (exit) the popup.

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

Re: PopUp Menu perceived anomaly

Post by Klaus » Thu Mar 16, 2023 2:23 pm

Oh, sorry, my fault. Yes, this should do the trick:

Code: Select all

on menuPick pitemname   
   switch pitemname
      case "The product is a consumable, normally sold in a shop, no invoice raised, for example, a packet of biscuits."
         put "consu" into field "type"
         send "mouseup" to btn "afterbiscuits"
         ## Misunderstood your first posting:
         exit menupick
         break
      case "It is a
...
If that does not work try this instaed of exit menupick -> exit to top

CAsba
Posts: 432
Joined: Fri Sep 30, 2022 12:11 pm

Re: PopUp Menu perceived anomaly

Post by CAsba » Thu Mar 16, 2023 2:43 pm

Thanks, Klaus, everything fine !

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

Re: PopUp Menu perceived anomaly

Post by dunbarx » Thu Mar 16, 2023 5:23 pm

CAsba.

Great news.

You can see that there is a strict syntax in LC that one has to know how to use. The very english-like structure of the language makes users assume that if a person can understand what they are talking about, then the LC parser ought to be able to as well.

This comes with practice. Know, however, that it never quite goes away completely, however experienced one gets. :wink:

Craig

Post Reply