Skip to main content
Known Participant
February 27, 2009
Question

CFSWITCH

  • February 27, 2009
  • 2 replies
  • 1013 views
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 has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
March 1, 2009
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.

Inspiring
February 28, 2009
> 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