Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using CFSWITCH

Status
Not open for further replies.

KevinFSI

Programmer
Nov 17, 2000
582
US
Quick question: Is it possible to use a <CFCASE VALUE=&quot;...&quot;> where &quot;value&quot; is a range of numbers, or are ranges only possible with <CFIF>?

For example...
Code:
<CFIF myRange GE 0 AND myRange LE 100>
Kevin
slanek@ssd.fsi.com
 
I don't think so, to my understanding the values in the <CFCASE> tag must be a constant value, you can't even use a CF variable in the CFCASE, it must be a &quot;constant value&quot;.

You could do <CFCASE VALUE=&quot;1,2,3,4,... all the way to.. 98,99&quot;>, but that would be a pain.

I'd say your better alternative would to use <CFIF>.
- tleish
 
Yep, sounds about right. I thought I'd ask anyway.

Thanks, Kevin
slanek@ssd.fsi.com
 
Yes you can. First you need to define your case, i.e.,
<case value=&quot;Something&quot;>

</cfcase>

Within the <cfcase></cfcase> you can then use your <cfif> statements.

Hope this helps. Yvette Ingram
Brainbench Certified
ColdFusion Application Developer
 
I knew you could use <CFIF> within <CFCASE> but if you're going to do that, aren't you losing most of what makes <CFSWITCH> more efficient?

I prefer <CFSWITCH> in most situations because it's reported to be more efficient than several <CFIF> statements. If I were to use the two together, how would I benefit? Is there any added value to putting <CFIF> inside a <CFSWITCH> statement? It actually ends up being more code. Kevin
slanek@ssd.fsi.com
 
CFSwitch/CFCase actually makes it extremely easy for you to match a expression with a range of values.

the CFCase tag supports an option Delimiters argument--the comma (,) is the default delimiter, but you can specify alternative delimiters like this:

Code:
<cfcase value=&quot;1:2:3:4:5&quot; delimiters=&quot;:&quot;>
blah blah
</cfcase>

I actually just bought a pretty good book that details this: &quot;Mastering Coldfusion 4.5&quot; by Arman Danesh and Kristin Aileen Motlagh. I would highly recommend picking up a copy for reference.
 
Cool, but what if your range is 1 - 10,000? Kevin
slanek@ssd.fsi.com
 
Oooo, yuk. Hadn't considered that. In that case,it would probably behoove you to use a [cfif #value# gt 0 and #value# lt 10000], which of course could be complicated if your values range from 1 to 10,000, but don't include ALL values between 1 and 10,000.

So, in a nutshell, um, good luck? Let us know if you find anything. {:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top