View comments | RSS feed

SetVariable

Description

This function is no longer required in well-formed ColdFusion pages.

Sets a variable in the name parameter to the value of the value parameter.

Return value

The new value of the variable.

Category

Dynamic evaluation functions

Syntax

SetVariable(name, value)

See also

DE, Evaluate, IIf

Parameters

Parameter Description
name
Variable name
value
A string, the name of a string, or a number

Usage

Before this function is called, the client variable must exist, and the cfapplication tag ClientManagement attribute must be set to "Yes".

Note:   If you concatenate string elements to form the name parameter, you can improve performance using the cfset tag, instead.

For example:

    <cfset "myVar#i#" = myVal>

is faster than:

    SetVariable("myVar" & i, myVal)

For more information, see Developing ColdFusion MX Applications with CFML.

Example

<h3>SetVariable Example</h3>

<cfif IsDefined("FORM.myVariable")>
<!--- strip out url, client., cgi., session., caller. --->
<!--- This example only lets you set form variables --->
<cfset myName = ReplaceList(FORM.myVariable,
 "url,client,cgi,session,caller", "FORM,FORM,FORM,FORM,FORM")>

<cfset temp = SetVariable(myName, FORM.myValue)>
<cfset varName = myName>
<cfset varNameValue = Evaluate(myName)>
<cfoutput>
  <p>Your variable, #varName#
  <p>The value of #varName# is #varNameValue#
</cfoutput>
</cfif>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


dkpo said on Apr 15, 2003 at 6:59 PM :
And further, the statement "For more information, see Developing ColdFusion MX Applications with CFML." doesn't really help much when that book runs OVER 900 PAGES!!

It would be much more helpful to be directed to a SPECIFIC PAGE OR CHAPTER in that book.
GiskardOlivaw said on Apr 29, 2003 at 5:38 PM :
I completely disagree with them saying a "well formed" page wouldn't use this. What about dynamic-creation of variables from a database? It's the only way to do it!

<CFSET DynamicVar = "ABC">
<CFSET SetVariable("#DynamicVar#", "Test Value")>
<CFOUTPUT>#ABC#</CFOUTPUT>
dkpo said on Apr 15, 2003 at 6:54 PM :
Anyone care to explain the statement at the top of this page "This function is no longer required in well-formed ColdFusion pages" ...???

Alternative syntax examples would be really be much more helpful than this ambiguous statement.
hlichtin said on May 7, 2003 at 2:58 PM :
In ColdFusion MX the following code should work. I chanbged the names so you can cut and paste it along with the previous example:

<CFSET DynamicVar2 = "ABD">
<CFSET "#DynamicVar2#" = "Test Value2">
<CFOUTPUT>#ABD#</CFOUTPUT>

The cross reference should be to the "Dynamic variabel naming without dynamic evaluation" section of Chapter 4, using Expressions and Pound Signs of the Developing Applications book.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt280.htm