View comments | RSS feed

Evaluate

Description

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.

Return value

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

Category

Dynamic evaluation functions

Syntax

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

See also

DE, IIf

Parameters

Parameter Description
string_expression1, string_expression2...
Expressions to evaluate

Usage

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 Developing ColdFusion MX Applications with CFML.

Example

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

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

Version 6

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

Comments


halL said on Apr 15, 2004 at 2:35 PM :
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.)
kodemonki said on Jan 4, 2008 at 12:33 PM :
Numbers less than 1 and greater than 0 (I haven't tried less than 0 and greater than -1) must have a leading zero, otherwise evaluate says . is an invalid parser construct.

Hopefully this will save someone a lot of time.

I'm not quite sure how to work around this if you create a string formula from variables stored in a database, since I don't know how to save a number as 0.2 instead of .2 . . .
halL said on Jan 4, 2008 at 12:48 PM :
I haven't tested this in CF 6, but CF 8 does not appear to have this issue.

 

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

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt176.htm