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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to reference a variable via a string?

Status
Not open for further replies.

jonhodgkinson

Programmer
Mar 5, 2002
7
GB
Hi, is it possible through CF to reference a variable via a string? i.e. I have the form variable 1_Email_145 and I want to get the value of this from by: function("1_Email_145")

I hope that makes sense, thanks for your help!
 
The first thing you should know is, you can't have a variable name that starts with a number, so FORM.1_Email_145 is not valid. To create dynamic variables, have a look at my response in this thread:

thread232-596971

-Tek
 
I had a similar problem to this, I used Evaluate("String") to solve the problem. However, I am now struggling with something else. I basically want to test if the variable is defined ie.

isdefined(Evaluate("String"))

but this keeps giving a syntax error.

Thanks in advance for any help.
 
IsDefined() performs an implicit evaluation, so you could do:
Code:
<cfset i = 1>
<cfif IsDefined(&quot;myvar&quot; & i)>
   <!--- Does the variable myvar1 exist? --->
</cfif>

-Tek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top