Skip to main content
Known Participant
Feb 27, 2009 7:55 PM UTC
Question

CFSWITCH

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.
This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

BKBK
Community Expert
Community Expert
Mar 1, 2009 8:42 PM UTC
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.

Translate
Inspiring
Feb 28, 2009 10:59 AM UTC
> Can I do :
> <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
Translate