[thelist] RE: What is the ColdFusion equivalent to eval()?

Ron Thigpen rthigpen at nc.rr.com
Tue Apr 24 10:47:08 CDT 2001


Jon, 

  You've actually got two related problems here.  The first is evaluating the
original set of related variables (myvar'x'), and the second is assigning values
to new set of related variables (mess'x').

 CF's Evaluate() function is just what you need for the first problem.
 CF's SetVariable() function gives you an easy way to solve the second.

Here's code:

<!--- assign input vars --->
<cfset myvar1="Hi">
<cfset myvar2="Hey">
<cfset myvar3="Hello">

<cfloop index=i from=1 to=3>
<cfset varname= 'myvar' & '#i#'><!--- set string value for input var name --->
<cfset thisMess= 'mess' & '#i#'><!--- set string value for output var name --->
<cfset temp = SetVariable(thisMess, evaluate(varname))><!--- assign value of
input var to named output var --->
</cfloop>

<cfoutput>#mess1#, #mess2#, #mess3#</cfoutput><!--- see the result --->

I think this is what you're looking for.

--Ron Thigpen



jon steele wrote:
 
> But I'm still having some trouble. I am trying to use
> my counter (i) in the name of the variables I am
> declaring, creating a list variables like myvar1,
> myvar2, etc. But I can't do this becuase CF tells me I
> can't use Evaluate on the left hand-side. Is there
> another way? This is what I was testing with:
> 
> <cfset mayvar1="Hi">
> <cfset mayvar1="Hey">
> <cfset mayvar1="Hello">
> 
> <cfloop index=i from=1 to=3>
> <cfset mess#i# = Evaluate("myvar#i#")>
> </cfloop>
> 
> <cfoutput>#mess1#, #mess2#, #mess3#</cfoutput>
> 
> I wasnt the above to write "Hi, Hey, Hello". As you
> can see I need to use the counter in the name of the
> new variables being created by the loop.
> 
> Jon.
> 
>




More information about the thelist mailing list