Switch Statement - multiple selection

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
stevewhyte
Posts: 25
Joined: Mon Oct 18, 2010 6:32 pm

Switch Statement - multiple selection

Post by stevewhyte » Wed Mar 02, 2011 9:03 am

Hi,

Me again. Sorry!

I'm trying to make use of a switch statement for multiple selection. Depending upon what the user enters, will depend on what message will be displayed. Here is what I have so far:

-----------

global choice

on mouseUp
ask "Please enter your colour"
put it into choice

switch
case choice "Red"
case choice = "Blood is red" into line 1 of field "output"

case choice "Blue"
case choice = "The sea is blue" into line 1 of field "output"

case choice "Black"
case choice = "Coal is black" into line 1 of field "output"

case choice "Green"
case choice = "Grass is green" into line 1 of field "output"

case choice "Yellow"
case choice = "The sun is yellow" into line 1 of field "output"

else

put "Sorry, there is no message for that colour." into line 1 of field "output"

end switch

end mouseUp
--------------------


It doesn't work because my structure is all wrong and I don't think a switch statement can contain an else.

Can anyone advise? Also, is it possible to also change the card colour so when the user enters a colour, the message is displayed and the card background changes colour at the same time?

Very kindest regards,

Steven :D

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Switch Statement - multiple selection

Post by Dixie » Wed Mar 02, 2011 10:52 am

Steven...

Yes, you have your 'switch' statements a little mixed up. I have attached a stack that should help you with your 'switch' statements and show you how to change the colour of the card as you want to do...

be well

Dixie
Attachments
switchColour.zip
(1.25 KiB) Downloaded 473 times

stevewhyte
Posts: 25
Joined: Mon Oct 18, 2010 6:32 pm

Re: Switch Statement - multiple selection

Post by stevewhyte » Wed Mar 02, 2011 11:50 am

Dixie,

Thank you so much for this. You have been most helpful!!

:mrgreen:

Post Reply