Button Drop-menu need help with script

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
Derek Henderson
Posts: 8
Joined: Mon Sep 24, 2012 5:37 pm

Button Drop-menu need help with script

Post by Derek Henderson » Tue Jun 28, 2016 10:56 am

Using LiveCode Community edition version 8.0.1 on Windows 10 laptop

I have a button with a dropdown menu. I have based my code on the code provided by the Menu Builder. The code is accepted without errors. In run mode menu items selected are ignored. Below is a copy of the script:

on menuPick pWhich
switch --pWhich
case "New"
go back --Does not work
answer pWhich--Insert script for New menu item here
break
case "Edit"
answer pWhich--Insert script for Edit menu item here
answer pWhich
break
case "Delete"
answer pWhich--Insert script for Delete menu item here
break
case "Print"
answer pWhich--Insert script for Print menu item here
break
case "Graphs"
answer pWhich--Insert script for Graphs menu item here
break
case "Backup"
answer pWhich--Insert script for Backup menu item here
break
case "Restore"
answer pWhich--Insert script for Restore menu item here
break
case "Import"
answer pWhich--Insert script for Import menu item here
break
case "Export"
answer pWhich--Insert script for Export menu item here
break
case "Backup"
answer pWhich--Insert script for Backup menu item here
break
case "Restore"
answer pWhich--Insert script for Restore menu item here
break
case "Preferences"
answer pWhich--Insert script for Preferences menu item here
break
case "Help"
answer pWhich--Insert script for Help menu item here
break
case "Exdit Program"
quit
answer pWhich--Insert script for Exit menu item here
break
end switch
end menuPick
I would be most grateful for any assistance.

Derek Henderson

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

Re: Button Drop-menu need help with script

Post by Klaus » Tue Jun 28, 2016 11:08 am

Hi Derek,

well, this should do the trick:

Code: Select all

on menuPick pWhich
  ## switch --pWhich
  switch pWhich
     case "New"
...
If you comment out the parameter -> pWhich, then the engine does not know
what exactly to "switch" and thus NO "case" will fit here!

And if you quit, the next line will of course never be executed:

Code: Select all

...
case "Exdit Program"
  quit
  answer pWhich--Insert script for Exit menu item here
break
...
Best

Klaus

Derek Henderson
Posts: 8
Joined: Mon Sep 24, 2012 5:37 pm

Re: Button Drop-menu need help with script

Post by Derek Henderson » Tue Jun 28, 2016 4:10 pm

Hi Klaus
Thanks for such a prompt reply.
I have made the changes. The answer statements appear to be ignored.See Below.

on menuPick pWhich
## switch --pWhich
switch pWhich
case "New"
answer pWhich--Insert script for New menu item here
break
case "Edit"
answer pWhich--Insert script for Edit menu item here
answer pWhich
break
case "Delete"
answer pWhich--Insert script for Delete menu item here
break
case "Print"
answer pWhich--Insert script for Print menu item here
break
case "Graphs"
answer pWhich--Insert script for Graphs menu item here
break
case "Backup"
answer pWhich--Insert script for Backup menu item here
break
case "Restore"
answer pWhich--Insert script for Restore menu item here
break
case "Import"
answer pWhich--Insert script for Import menu item here
break
case "Export"
answer pWhich--Insert script for Export menu item here
break
case "Backup"
answer pWhich--Insert script for Backup menu item here
break
case "Restore"
answer pWhich--Insert script for Restore menu item here
break
case "Preferences"
answer pWhich--Insert script for Preferences menu item here
break
case "Help"
answer pWhich--Insert script for Help menu item here
break
case "Exdit Program"
answer pWhich--Insert script for Exit menu item here
quit
break
end switch
end menuPick

I must be still doing something wrong

Regards
Derek Henderson

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

Re: Button Drop-menu need help with script

Post by Klaus » Tue Jun 28, 2016 4:22 pm

Hi Derek,

very strange, just made a test with your script and it works as expsected!?

To be sure, your menuitems (text of button) are in fact:
New
Edit
Delete
Print
Import
Export
etc...
are they?


Best

Klaus

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Button Drop-menu need help with script

Post by SparkOut » Tue Jun 28, 2016 4:22 pm

Add a default block which answers pWhich just to see if the switch block is working.
If so, then try changing the switch tests to

case pWhich = "New"
answer "New code goes here"
break

etc etc

hpsh
Posts: 52
Joined: Tue Aug 25, 2015 8:06 pm

Re: Button Drop-menu need help with script

Post by hpsh » Thu Jun 30, 2016 1:35 am

if it is the exit switch that is a problem, it is a spelling error there (in the word "Exdit")

Code: Select all

case "Exdit Program"
answer pWhich--Insert script for Exit menu item here
quit
break
end switch
end menuPick
should probably be

Code: Select all

case "Exit Program"
answer pWhich--Insert script for Exit menu item here
quit
break
end switch
end menuPick

Derek Henderson
Posts: 8
Joined: Mon Sep 24, 2012 5:37 pm

Re: Button Drop-menu need help with script

Post by Derek Henderson » Thu Jun 30, 2016 4:09 pm

Hi Klaus and hpsh
Tried the latest suggestions including the fix of error "exdit", however no luck.
Could it be that I originally copied all the code generated by the Menu Builder and thereafter manipulated the code to what I wanted.

I will clear all code and re-enter line by line.

Presumably it is not the copy from 8.01 to Community 7 causing this.
I will revert with the results.

Regards and many thanks for your help
Derek Henderson

hpsh
Posts: 52
Joined: Tue Aug 25, 2015 8:06 pm

Re: Button Drop-menu need help with script

Post by hpsh » Thu Jun 30, 2016 5:43 pm

ok, anyway this is my code under a pulldownmeny button

Code: Select all

on menuPick pWhich
   ## switch --pWhich
   switch pWhich
      case "New"
         answer pWhich--Insert script for New menu item here
         break
      case "Edit"
         answer pWhich--Insert script for Edit menu item here
         answer pWhich
         break
      case "Delete"
         answer pWhich--Insert script for Delete menu item here
         break
      case "Print"
         answer pWhich--Insert script for Print menu item here
         break
      case "Graphs"
         answer pWhich--Insert script for Graphs menu item here
         break
      case "Backup"
         answer pWhich--Insert script for Backup menu item here
         break
      case "Restore"
         answer pWhich--Insert script for Restore menu item here
         break
      case "Import"
         answer pWhich--Insert script for Import menu item here
         break
      case "Export"
         answer pWhich--Insert script for Export menu item here
         break
      case "Backup"
         answer pWhich--Insert script for Backup menu item here
         break
      case "Restore"
         answer pWhich--Insert script for Restore menu item here
         break
      case "Preferences"
         answer pWhich--Insert script for Preferences menu item here
         break
      case "Help"
         answer pWhich--Insert script for Help menu item here
         break
      case "Exit Program"
         answer pWhich--Insert script for Exit menu item here
         quit
         break
   end switch
end menuPick
also, in propertys to the pulldownmeny i have the choises in the text part

Code: Select all

New
Edit
Delete
Print
Graphs
Backup
Restore
Import
Export
Backup
Restore
Preferences
Help
Exit Program
also including my code

i use livecode 8.0.1

just one thing, almost everyone here is better then me :-) if someone disagree with me, i am most likely wrong.
Attachments
pulldown.zip
(1.01 KiB) Downloaded 234 times

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

Re: Button Drop-menu need help with script

Post by Klaus » Thu Jun 30, 2016 7:21 pm

And of course everything works fine in your stack here on my Mac with LC 8.01! :shock:

hpsh
Posts: 52
Joined: Tue Aug 25, 2015 8:06 pm

Re: Button Drop-menu need help with script

Post by hpsh » Fri Jul 01, 2016 8:02 am

well, should probably said that i also use mac. osx 10.11.5. el capitan.

think only thing i changed was removing "d" from "exdit", and put in the choices in the pulldownmeny.

but pretty easy to to overlook something, remember some pretty amazing errors i did in borland turbo c in then i was young.

if i have space to it, i can try to install linux on my mac, and try the script there, but has to wait to i am home, begin to wonder if its a windows bug.

did try to install linux in a wm, and think i just has to leave that to anyone else, seems to be always some "usefull" function that kill any hope to test it for me.

Post Reply