SetVariable

Description

Sets the variable specified by name to value; returns the new value of the variable.

Category

Dynamic evaluation functions

Syntax


SetVariable(name, value) 

See also

DeleteClientVariable, GetClientVariablesList

Parameters

Parameter
Description
name
Variable name
value
String or number assigned to the variable

Usage

The client variable must exist before using this function. The ClientManagement attribute of cfapplication tag must have been set to "Yes" for this template.


Note

If you concatenate string elements to form the name parameter, you can improve performance using CFSET instead.


For example:

    <cfset "myVar#i#" = myVal>

is faster than:

    SetVariable("myVar" & i, myVal)

Example

<!--- This example shows SetVariable --->

<html>

<head>

<title>

SetVariable Example

</title>

</head>



<body bgcolor = silver>

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

...



Banner.Novgorod.Ru