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!

Composing Variables with CFSET

Status
Not open for further replies.

metaphiz

Programmer
Jun 30, 2004
91
0
0
US
I need to combine a number of variables used to generate a CAPTCHA image into one variable using CFSET. The first character of the CAPTCHA is called something like var1, the second is something like var2, etc.

Of course I've gotten errors when I try it like this:

<cfset CaptchaCode = var1var2var3var4var5>
or like this
<cfset CaptchaCode = #var1##var2##var3##var4#var5#>
or like this
<cfset CaptchaCode = "var1var2var3var4var5">
or like this
<cfset CaptchaCode = (var1)(var2)(var3)(var4)(var5)>

I also tried a list, but I don't want the commas. How do you indicate to CF that you are combining several variables into one without calling a non-existent variable? Must be some syntax needed with CFSET that I don't know about. Anyone?
 
In CF, the concatenation operator is "&"

Code:
<cfset someVariable = var1 & var2>

Technically, this is valid as well. Though personally, I prefer the first option.

Code:
<cfset someVariable = "#var1##var2">


----------------------------------
 
You could use cfparam to default the values. Then use something like:

Code:
<cfparam name="var1" default="">
<cfparam name="var2" default="aa">
<cfparam name="var3" default="">
<cfparam name="var4" default="bb">

<cfset CaptchaCode = var1 & var2 & var3 & var4>
<cfoutput>#CaptchaCode#</cfoutput>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top