Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluate help please! 1

Status
Not open for further replies.

lminmei

Programmer
Feb 1, 2000
111
0
0
US
final result = "attributes.Field1", "attributes.Field2", etc

i create a query called "getNum" to get a list of numbers where then i have to append those numbers to the end of a fieldname called field...
so how can i evaluate this expression? where i have a variable inside another variable?

for instance:
#attributes.Field#getNum.Name##

i know that doesn't work...
so i have to use the Evaluate function... how would i do that?
 
Here is an example of how to use evaluate().
Code:
<cfset a1 = "Hello">
<cfset a2 = "There">
<cfset Prefix = "a">
<cfset idx = 1>
<cfloop from = "#idx#" to = 2 index = "i">
 <cfset varValue = evaluate(prefix&i)>
 <cfoutput>
  #varValue# &nbsp;
 </cfoutput>
</cfloop>

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Hey lminmei,

the exact code you'll be after would be:

final result =
<cfLoop Query="getNum">
" #Evaluate("attributes.field" & getNum.Name)# ",
</cfLoop>

or to catch it as a commaseperated list in a variable try:

<cfSet sResult = "">

<cfLoop Query="getNum">
<cfSet sResult = sResult & Evaluate("attributes.field" & getNum.Name) & ",">
</cfLoop>

<cfOutput> #sResult# </cfOutput>



We never fail, we just find that the path to succes is never quite what we thought...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top