Page 1 of 1
Button Drop-menu need help with script
Posted: Tue Jun 28, 2016 10:56 am
by Derek Henderson
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
Re: Button Drop-menu need help with script
Posted: Tue Jun 28, 2016 11:08 am
by Klaus
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
Re: Button Drop-menu need help with script
Posted: Tue Jun 28, 2016 4:10 pm
by Derek Henderson
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
Re: Button Drop-menu need help with script
Posted: Tue Jun 28, 2016 4:22 pm
by Klaus
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
Re: Button Drop-menu need help with script
Posted: Tue Jun 28, 2016 4:22 pm
by SparkOut
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
Re: Button Drop-menu need help with script
Posted: Thu Jun 30, 2016 1:35 am
by hpsh
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
Re: Button Drop-menu need help with script
Posted: Thu Jun 30, 2016 4:09 pm
by Derek Henderson
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
Re: Button Drop-menu need help with script
Posted: Thu Jun 30, 2016 5:43 pm
by hpsh
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.
Re: Button Drop-menu need help with script
Posted: Thu Jun 30, 2016 7:21 pm
by Klaus
And of course everything works fine in your stack here on my Mac with LC 8.01!

Re: Button Drop-menu need help with script
Posted: Fri Jul 01, 2016 8:02 am
by hpsh
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.