ColdFusion
  Home arrow ColdFusion arrow Page 3 - Everything You Must Know About ColdFusion ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
COLDFUSION

Everything You Must Know About ColdFusion Variables
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 4
    2005-08-15

    Table of Contents:
  • Everything You Must Know About ColdFusion Variables
  • Developing ColdFusion Content
  • Variable definition with CFSET tag
  • Variable by assigning statements in CFSCRIPT
  • Scope of a variable
  • Data Type Category of Variables
  • How do we name a variable?

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Everything You Must Know About ColdFusion Variables - Variable definition with CFSET tag


    (Page 3 of 7 )

    In the earlier article the <cfset> tag was introduced. This tag sets the value of a variable. Trying to use a variable before it is assigned a value results in an error. The best practice is to test its existence before using it. Here is an example. This file undefined.cfm would produce an error, since the variable jac is not defined as shown in the picture below the code. As indicated in the error message, a more robust error message can be generated after changing the settings in the ColdFusion Administrator. We postpone this for later.

    Syntax
    <CFSET variable_name=expression>
    
    
    <cfoutput>#jac#</cfoutput>
    

    Variable assignment with <cfparam> tag

    The above problem could have been identified before calling the variable, by using some kind of logic. However, there is yet another way of avoiding the issue. This is by using the <cfparam> tag to define the variable. In fact, <cfparam> can not only be used in the context of a variable, but can also be used in a much wider range of variables, including simple data types as well as complex data types. Here is an example of its usage.

    Syntax
    <CFPARAM NAME="param_name"
    TYPE="data_type"
    DEFAULT="value">
    
    <!---Variable definition using CFPARAM tag--->
    <!---Usage of <cfparam>--->
    <!---If named parameter does not exist, 
    it returns the default specified---> <cfparam name="jac" default="Okidoki"> <cfoutput> Variable 'jac' is not defined<br/> </cfoutput> <!---<cfset jac="Jay">---> <cfoutput> My name is #jac#. </cfoutput> <hr> <cfparam name="jac" default="Okidoki"> <cfoutput> Variable 'jac' is defined as 'Jay'<br/> </cfoutput> <cfset jac="Jay"> <cfoutput> My name is #jac#. </cfoutput>

    Now you look at the browser output when this file cfparam.cfm is browsed. In the first part, a variable was not defined and therefore the display was a default value. In the second part, a variable did exist and was defined. In this case the value of the variable was displayed.

    More ColdFusion Articles
    More By Jayaram Krishnaswamy


       · I very much would like to have your comments on this article. [b]Macromedia[/b] has...
     

    COLDFUSION ARTICLES

    - How to Access a SQL Anywhere Database with C...
    - CFXML: Probing XMLDOM in ColdFusion
    - Creating a Web Service with ColdFusion: the ...
    - CFAjax: What it is and How to Use it
    - Querying SQL 2000 Server from ColdFusion
    - Introduction to ColdFusion Markup Language, ...
    - Introduction to ColdFusion Markup Language
    - Databases and Dreamweaver MX 2004, concluded
    - Databases and Dreamweaver MX 2004
    - Welcome to Coldfusion MX 6.1, concluded
    - Welcome to Coldfusion MX 6.1
    - What You Must Know About ColdFusion Flow-Con...
    - What You Must Know About Operators in ColdFu...
    - Everything You Must Know About ColdFusion Va...
    - My First Application on ColdFusion MX Server







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway