×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

The Evalute() Function by pcorreia
Posted: 24 May 02

Consider this example:

   <cfset myVar = "foo">
   <cfset myVarName = "myVar">

Obviously, one way to get the value of myVar is #myVar#.  But if I don't know what the name of the variable is going to be (which is sometimes the case with query or form variables), I can't do that.  I know that the name of the variable is stored in the variable #myVarName#, so I need a way to say to the ColdFusion engine, "Take the value of the variable 'myVarName', then evaluate that as the name of another variable".  Since ColdFusion doesn't speak english, exactly, we have the Evaluate() function to tell it to do that.  One way to accomplish the above example would be:

   #Evaluate("#myVarName#")#

Which says (from inside out):
  1. Extract the value of the variable myVarName (which is a string).

  2. Treat that string like it was the name of a variable, and get the value of that variable.

In ColdFusion documentation, this is known as Dynamic Evaluation.  There's a simpler way to write the Evaluate() function, which takes advantage of the fact that anywhere a function or expression expects a string in quotes, it will take an unquoted variable name instead:

   #Evaluate(myVarName)#

So this evaluates not the string "myVarName", (which in this example evaluates to "myVar"), but the value of the variable "myVarName" ("myVar", which evaluates to "foo").

Hope this helps out.

Back to Adobe FAQ Index
Back to Adobe Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close