House of Fusion
Home of the ColdFusion Community
Hostmysite Dedicated Hosting
Subscribe Now
Fusion Authority Quarterly Update - ColdFusion 8 Special Edition

For ColdFusion hosting try HostMySite.com.
Search over 2,500 ColdFusion resources here  >>>      

CFSCRIPT: Variable Assignment

3Variable Assignment
3.1 A variable assignment is any operation where a variable name is placed on the left hand side of an equal sign (=) and some value or operation is placed on the right hand side. This value or the result of the operation will be assigned to a variable with a reference name equal to the left hand side value.
3.2All variable assignments must end in a semicolon (;).
3.3 Possible values for a variable are:
     Numbers
     Quoted text strings
     Quoted text strings with delimited variables inside (using pound signs)
     Previously defined variables
     Results of a function
     Mathematical or string concatenation operations
<CFSCRIPT>
     variable=5;
     Variable="text value";
     variable="the date is #now()#";
     variable=now();
     variable=othervariable;
     variable=5+5;
     variable="The time is "&timeformat(now());
</CFSCRIPT>
3.4 Setting a dynamic variable name can be done using the standard method of placing the dynamic portion of the variable name within pound signs (#) and then placing it (and any text portion of the variable name) within quotes. It is preferred to use the SetVariable() function rather than this method of setting a dynamic variable name.
<CFSCRIPT>
     // Set a variable called dynamicvariable with a value of "variablename"
     dynamicvariable = "variablename";
     // Set a variable called variablename with a value of "text value".
     "#dynamicvariable#" = "text value";
     // Set a variable called Myvariablename with a value of 5
     "My#dynamicvariable#" = 5;
</CFSCRIPT>


User Contributed Notes


Add a Note


CFScript