Discussion:
CFSWITCH
(too old to reply)
alecken
2009-02-27 19:55:51 UTC
Permalink
I know I can do <CFCASE value="1,2,3,4,5,6"> do something </cfcase>
But if I'm evaluation 2 variable values, Can I do :
<cfswitch expression="#variable1# , #variable2#">
<cfcase value="a">
do 1 + 1 = 2
</cfcase>
</cfswitch>

Instead of
<cfif #Variable1# IS "abcd" OR #Variable2# IS "xyz">>
do 1 + 1 =2
</cfic>

So basically if Variable1 IS "ABCD" OR Variable2 IS "xyz" do the same thing
I guess nothing is wrong with using cfif instead of cfswitch but in my
application there are too mane nested cfif already.
Adam Cameron
2009-02-28 10:59:04 UTC
Permalink
Post by alecken
<cfswitch expression="#variable1# , #variable2#">
No.

But you could perhaps do some jiggery-pokery with the two values:

<cfset myChar="a"><!--- could be a-z --->
<cfset myDigit = 1><!--- could be 0-9 --->

<cfswitch expression="#myChar##myDigit#">
<cfcase value="a1"></cfcase>
<!--- ... --->
<cfcase value="e6"></cfcase>
<!--- etc --->

Or some variation on that notion.

Not a perfect technique, nor will it work for all situations, but it might
be possible in your one?
--
Adam
BKBK
2009-03-01 20:42:43 UTC
Permalink
Alecken, something like that is possible. But not with cfswitch. You can make
the selection using cfcase's delimiters attribute. Here's an example to
illustrate.



<cfloop list="abcd,efg,kk,mn,xyz,oo,pqrs,hhh" index="listElement">

<cfswitch expression="#listElement#">
<cfcase value="abcd;xyz" delimiters=";">
case 1: <cfoutput>#listElement#</cfoutput><br>
</cfcase>
<cfcase value="kk|oo-hhh" delimiters="|-"><!--- two or more delimiters
possible--->
case 2: <cfoutput>#listElement#</cfoutput><br>
</cfcase>
<cfcase value="efg,mn,pqrs" delimiters=","><!--- comma is default delimiter
--->
case 3: <cfoutput>#listElement#</cfoutput><br>
</cfcase>
</cfswitch>

</cfloop>

Loading...