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

Ron Thigpen rthigpen at nc.rr.com
Tue Apr 24 12:13:19 CDT 2001

[sent this to thelist, but I never saw it...]


  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 --->

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

I think this is what you're looking for.

--Ron Thigpen

jon steele wrote:
> You have two ways that you can set a dynamic var:
> 1) Use quotes:
> <CFSET NAME="ray">
> <CFSET "Hoo#Name#" = 1>
> will create a bar called HooRay.
> 2) Use the SetVariable() function. See docs.
> Ray Camden
> .sigless today
> -----Original Message-----
> From: jon steele
> Thanks Lindsay,
> 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">
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt !

More information about the thelist mailing list