troubleshooting Question

Should I be using an Array or Structure here? I get an error when trying to use cfset with a dynamic variable...

Avatar of Ike23
Ike23Flag for United States of America asked on
Web Servers
3 Comments1 Solution218 ViewsLast Modified:
I have the joyous task of migrating a bunch of non-normalized data into a new normalized database and have run into a problem.  One of the database fields contains a list string of numbers delimited by the | bar.  I have 4 categories that I can optionally set and I am using the <cfswitch><cfcase> method to map the old values to the new values.  The problem is that I am trying to dynamically set the variable name inside of a loop and CF gives me an error.  Here's my example code:

<!--- SET UP THE 4 CATEGORY VARIABLES WITH DEFAULTS OF ZERO AND OVERRIDE THE VALUES IF MATCHES ARE FOUND --->
      <cfparam name="CATEGORY1" default="0" type="numeric">
      <cfparam name="CATEGORY2" default="0" type="numeric">
      <cfparam name="CATEGORY3" default="0" type="numeric">
      <cfparam name="CATEGORY4" default="0" type="numeric">

<cfset catNumber = 0>
      <cfloop index="cat" list="#CATLIST#" delimiters="|">
            
           <cfset catNumber = catNumber + 1>
            
            <cfswitch expression="#cat#">

                  <cfcase value="6"><cfset CATEGORY#cat# = "1"></cfcase>*****HERE'S WHERE THE ERROR OCCURS******
                  <cfcase value="7"><cfset CATEGORY#cat# = "3"></cfcase>
                                                 <cfdefaultcase>
                             <cfset CATEGORY#cat# = "0">
                     </cfdefaultcase>
                                 </cfswitch>

Then I do a database insert using the Category1 - 4 variables here.

      </cfloop>


Is there a way to do this using an array or structure or am I going about this all wrong?  Thanks for any advice!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros