Since no one has said it yet, I will :-) Alan that way may not work in
future versions of CF, the better way is to use the SetVariable() function.
Syntax SetVariable(name, value)

<cfset var = "MyDynamicVariable">
<cfloop from="1" to="20" index="i">
<cfset rs = SetVariable(var, i)>
</cfloop>

Of course the above code would end up just overwriting itself with the end
result being MyDynamicVariable = 20, but the point is clear enough.
Also the SetVariable() function works with Regular expressions like so...

<cfloop from="1" to="20" index="i">
<cfset rs = IIF(i = 10, "SetVariable(var, i)", "SetVariable(var,"10 not
found!"))>
</cfloop>

In the above example MyDynamicVariable ends up evaluating to 10 of course.
If i had not equaled 10 in the loop, MyDynamicVariable would equal "10 not
found!".

btw, nice web site Allan...when are you going to put up a bigger picture of
that calendar? ;-)

jon
----- Original Message -----
From: "Allan Pichler" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Wednesday, December 20, 2000 6:37 PM
Subject: RE: dynamically naming variables


> This is how i use dynamic variable names on the left side of a cfset ....
> there's probably other ways to do it too....
>
> <CFLOOP from="1" to="20" index="i">
> <CFSET varname = "myvar" & i>
> <CFSET "#varname#" = i>
> </CFLOOP>
>
> Allan Pichler
> Machine Dreams Inc.
>
>
> -----Original Message-----
> From: Jay Brushett [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 20, 2000 7: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
> [EMAIL PROTECTED]
>
> 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 > < > < > < >
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to