A curious case (fixed typo)

Jim Ault jimaultwins at yahoo.com
Wed Mar 2 20:25:20 EST 2011


was:
> case (testValue is among the words IN "pink coral azure maize")

should be:
      case (testValue is among the words "pink coral azure maize")


On Mar 2, 2011, at 5:03 PM, Jim Ault wrote:

>
> On Mar 2, 2011, at 3:19 PM, Peter Haworth wrote:
>
>> Switch is definitley very handy but I wish it was more flexible.   
>> As far as I can tell, the case statement can only test for  
>> equality, for example:
>>
>> switch myvar
>> 	case begins with "xyz"
>>
>> ... generates an error as does anything else other than just a  
>> straight value on the case line.
>>
>> I know you can do
>>
>> switch
>> 	case myVar begins with "xyz"
>> ...just seems like conditions other than = would be more elegant on  
>> the case line.
>
> You can actually test for anything that resolves to true or false.
>
> put (the width of this stack div 2) > 154 into testValue
>
> put the locktext of fld 1 into testValue
>
> get the script of this stack
> put the number of lines in IT into testValue
>
> switch testValue
>     case true
>
> ----------------------
> put the textcolor of fld 1 into testValue
>
> switch testValue
>   case "red"
>   case "yellow"
>   case "orange"
> 	put "red" into newFontColor
>        break
>   case "green"
>   case "blue"
>   case "purple"
> 	put "green" into newFontColor
>        break
>   case (testValue is among the words "pink coral azure maize")
>        put "darkBlue" into newFontColor
>        break
>   default
> 	put "black" into newFontColor
> end switch
>
> set the textcolor of fld 1 to newFontColor
>
> Hope this gives you many ideas.

Jim Ault
Las Vegas






More information about the use-livecode mailing list