Here is a quick example of dynamic variable usage.
<cfset listVarNames = "foo,bar,dynamic,variables,rule">
<cfloop list="#listVarNames#" index="i"> <cfset "#i#DynamicVars" = "#i#DynamicVars"> <cfoutput>#Evaluate(i & "DynamicVars")#</cfoutput> </cfloop>
<cfoutput><br>#fooDynamicVars#<br>#barDynamicvars#<br>#dynamicDynamicVars#<b r>#variablesDynamicVars#<br>#ruleDynamicVars#</cfoutput>
OUTPUTS:
fooDynamicVars barDynamicVars dynamicDynamicVars variablesDynamicVars ruleDynamicVars fooDynamicVars barDynamicVars dynamicDynamicVars variablesDynamicVars ruleDynamicVars
Thats all it takes. (sneaky ehh?:)
There are a few "rules" if you will about your dynamic variables and the names they can have numbers, letters and underscores.
You must start a variable with a letter.
CF Interprets upper and lower case to be the same , no case sensitivity.
Well, that's a quick and dirty version of the rules for using dynamic variables (and cf variables in general)
You cant really "assign" a value to a coldfusion function, CF does nto grock that. If what your trying to do did not fit into the rules I just mentioned you probably can't do it :)
:-) BTW, if you find the cfset line confusing replace it with
<cfset "#i#DynamicVars" = "Just a plain ole string going into my dynamic variable">
Jeremy Allen elliptIQ Inc.
>-----Original Message----- >From: Jay Brushett [mailto:jay@zeddcomm.com] >Sent: Wednesday, December 20, 2000 10:54 AM >To: CF-Talk >Subject: dynamically naming variables > > > >Hi, > >I need to use the Evaluate function to dynamically name variables in a ><cfloop>. >Using the function on the right hand side of a cfset works fine of course >but CF won't let me use it on the left hand side (i.e. the variable name). > >Any ideas would be greatly appreciated. > >TIA, > >Jay >< > < > < > < > < Strategy ~ Creativity ~ Technology > < > < > < > < > < > > >Jay Brushett >jay@zeddcomm.com > >Developer > >< ZeddComm Inc. > >2nd Floor, The Tower | 100 Signal Hill Road >St. John's, Newfoundland | Canada A1A 1B3 >Main: 709.570.5669 | Fax: 709.739.9003 >Web: www.zeddcomm.com >< > < > < > < St. John's ~ New York ~ Newport Beach ~ Ottawa > < > < > < > > > > >