Concatenate ColdFusion

Hey guys.  This is very simple and I cannot figure it out.

Is this code possible?

<cfset cnt =  1>

<cfif isdefined('test#cnt#') and test#cnt# neq "">
  ...

</cfif>


I am trying to get the value of variable test1.
jramos74Asked:
Who is Participating?
 
incapitalCommented:
Also, remember that the second part of your if statement is actually checking for a value, so you'll have to use evaluate there...

<cfset count = 1>
<cfset "test#count#" = 1>
<cfoutput>#evaluate("test#count#")#</cfoutput>

<cfif isDefined("test#count#") and evaluate("test#count#")>
      I exist!
</cfif>
0
 
incapitalCommented:
Try evaluate("test#cnt#") to get the value held by a dynamically named variable.
0
 
jramos74Author Commented:
Thanks incapital.

That is actually my previous code.  Here is tha actual code:

<cfif isdefined(evaluate("test#cnt#"))>

I am getting an error message.  I know something is wrong with my syntax.
0
 
incapitalCommented:
Right. Evaluate returns the value held by the dynamic variable, so it's not actually checking to see if the value exists.

You actually don't need to use evaluate in that case. Maybe the code below will help:

<cfset count = 1>
<cfset "test#count#" = 1>
The value of my dynamic variable is:<cfoutput>#evaluate("test#count#")#</cfoutput>

<cfif isDefined("test#count#")>
      I exist!
</cfif>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.