View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > Evaluate PreviousNext

Evaluate

Evaluates one or more string expressions, dynamically, from left to right. (The results of an evaluation on the left can have meaning in an expression to the right.) Returns the result of evaluating the rightmost expression.

An object; the result of the evaluation(s).

Dynamic evaluation functions

Evaluate(string_expression1 [, string_expression2 [, ... ] ] )

DE, IIf

Parameter

Description

string_expression1, string_expression2...

Expressions to evaluate

String expressions can be complex. If a string expression contains a single or double quotation mark, it must be escaped.

This function is useful for forming one variable from multiple variables. For example, to reference a column of the query qNames with a variable, var, using an index value to traverse rows, you could use the following code:

<cfset var=Evaluate("qNames.#colname#[#index#]")>

For more information, see Using Expressions and Pound Signs in Developing ColdFusion MX Applications.

<!--- This shows the use of DE and Evaluate --->
<h3>Evaluate Example</h3>
<cfif IsDefined("FORM.myExpression")>
<h3>The Expression Result</h3>
<cftry>
<!--- Evaluate the expression --->
<cfset myExpression = Evaluate(FORM.myExpression)>
<!--- Use DE to output the value of the variable, unevaluated --->
<cfoutput>
<I>The value of the expression #Evaluate(DE(FORM.MyExpression))#
is #MyExpression#.</I>
</cfoutput>
...

Contents > CFML Reference > ColdFusion Functions > Evaluate PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


halL said on Apr 15, 2004 at 2:37 PM :
This page is a little skimpy. Here is some information we posted in response to an inquiry on the ColdFusion MX (6) version of the page:

The Evaluate function dynamically parses and evaluates an expression at run time. The Evaluate function can increase processing time compared to other techniques of getting dynamic values in ColdFusion because ColdFusion must parse and compile the expression that the function contains at run time, not just compile time.

In many cases you can avoid using the evaluate function by putting variable data and expressions in pound signs in ColdFusion cfoutput regions, or by using the cfset function with an expression.

For example, the following example sets a dynamically named variable without using Evaluate:

<cfset var1= "x">
<cfset "#var1#" = "My value">
<cfoutput>#x#</cfoutput><br>

You use the Evaluate function if you have a variable (var1) that contains the name of a variable (var2), and need to get the value of var2, as in the following example:

<cfset var1="var2">
<cfset var2="3">
<cfoutput>#Evaluate(var1)#</cfoutput>

Evaluate can also be useful in complex cases, where other techniques could result in convoluted code.

For information on the Evaluate function and how you can avoid using it, see http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/exprea29.htm and the pages that follow it. (Click the right arrows at the top or bottom of the page.)
a440guy said on May 26, 2004 at 11:26 AM :
To help in the understanding of this function, I would add:

<cfoutput>#varname#</cfoutput>

is EXACTLY the same as

<cfoutput>#Evaluate("varname")#</cfoutput>
halL said on Jun 2, 2004 at 3:06 PM :
In response to a440guy:
These two techniques will display the same results.
However, the code paths for the two differ, and as described in my previous posting, Evaluate requires more processing time than other techniques.
We would recommend the direct <cfoutput>#varname#</cfoutput> because it is more efficient.
smaglio said on Nov 17, 2004 at 2:44 PM :
I was trying to toy around with the information you gave above and got kinda confused when I tried this:

<cfset j = structNew() />
<cfset name = "n" />
<cfset k = structNew() />
<cfset l = structNew() />
<cfset j.n = 1 />
<cfset k.l.n = 2 />

<cfoutput>#j.n#</cfoutput><br />
<cfset 'j.#name#' = 'k.l.#name#' />
<cfoutput>#j.n#</cfoutput><br />

which gives the output of:
1
k.l.n

and then I tried:

<cfset j = structNew() />
<cfset name = "n" />
<cfset k = structNew() />
<cfset l = structNew() />
<cfset j.n = 1 />
<cfset k.l.n = 2 />

<cfoutput>#j.n#</cfoutput><br />
<cfset 'j.#name#' = evaluate('k.l.#name#') />
<cfoutput>#j.n#</cfoutput><br />

which gave the output of:
1
2

It almost seemed liked the left hand side of = within the <cfset> was automatically processed through an evaluate(), while the right hand side was not.

Is there a reason for this, what really happens during a <cfset>.
springdotnet said on Jun 13, 2005 at 9:19 PM :
Response to smaglio's comments:

I think the results that you got from your testing is what supposed to be.
In my understand, if there is a expression on the left side of the "=", it will be evaluated automatically before assign the right side value to it. That is to say, ColdFusion treats the following statements as the same:

<cfset 'j.#name#' = 'k.l.#name#' />
<cfset Evaluate('j.#name#') = 'k.l.#name#' />

Am I right?

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functi76.htm