Thanks for the replys.

I was hoping to avoid if... elseif... elseif... else.... type code.  And I
don't think the dynamic includes are the best answer in our case (although
it is a creative solution that might work for us elsewhere...).

I think we're stuck with changing our IDs in the application.cfm, AND the
page with the switch block.  

Thanks anyways.

Shawn

-----Original Message-----
From: Barney Boisvert [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 26, 2003 4:07 PM
To: CF-Talk
Subject: RE: Using variables in a Switch case?


You could do this:

-- main_template.cfm --
<cfset nID = 3 />
<cfinclude template="case_#nID#.cfm" />

-- case_2.cfm --
<br />Two

-- case_3.cfm --
<br />three

Not quite as easy to edit a several cases at once, but if the cases are
reasonably separate, that might provide exactly the behaviour you want.

barneyb

---
Barney Boisvert, Senior Development Engineer
AudienceCentral (formerly PIER System, Inc.)
[EMAIL PROTECTED]
voice : 360.765.8080 x12
fax   : 360.647.5351

www.audiencecentral.com

> -----Original Message-----
> From: Shawn Grover [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 26, 2003 2:46 PM
> To: CF-Talk
> Subject: Using variables in a Switch case?
>
>
> CF 5 doesn't like this:
>
> <cfset nID = 3>
> <cfset nTest1 = 2>
> <cfset nTest2 = 3>
> <cfswitch expression="#nID#">
>       <cfcase value="#nTest1#">
>               <br>Two
>       </cfcase>
>       <cfcase value="#nTest2#">
>               <br>three
>       </cfcase>
> </cfswitch>
>
> It throws an error saying the cfcase must have a constant value.  So, if I
> do this instead:
>
>       <cfcase value="2">
>               <br>Two
>       </cfcase>
>       <cfcase value="3">
>               <br>three
>       </cfcase>
>
> all works as expected.
>
> The downside is that we have a large number of items where their
> IDs will be
> changing on a regular basis (update, and replace in a different system
> assigns a new ID - our code is keyed on that ID).  We are assigning these
> IDs into a structure in application.cfm to minimize the number of
> changes we
> need to make when the IDs change.  But, this switch block doesn't
> like that
> plan.  Is there any way to do this with the variables?
>
> Thanks in advance.
>
> Shawn
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to