View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > SetVariable PreviousNext

SetVariable

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.

The new value of the variable.

Dynamic evaluation functions

SetVariable(name, value)

DE, Evaluate, IIf

Parameter

Description

name

Variable name

value

A string, the name of a string, or a number

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

You can use direct assignment statements in place of this function to set values of dynamically named variables. To do so, put the dynamically named variable in quotation marks and pound signs (#); for example:

<cfset DynamicVar2 = "ABD"> 
<cfset "#DynamicVar2#" = "Test Value2"> 

Also, the following lines are equivalent:

<cfset "myVar#i#" = myVal>
SetVariable("myVar" & i, myVal)

For more information, see Using Expressions and Pound Signs in Developing ColdFusion MX Applications.

<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>

Contents > CFML Reference > ColdFusion Functions > SetVariable PreviousNext

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

Version 6.1

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

Comments


Scatterblak said on Apr 22, 2005 at 11:28 AM :
regarirding this opening statement: "This function is no longer required in well-formed ColdFusion pages." -- This is incorrect. In advanced applications where cf is used to create things like scripting engines or dynamic ad-hoc data manipulation, setvariable is still useful.

 

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

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functa82.htm