ColdFusion
  Home arrow ColdFusion arrow Page 6 - 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 
VeriSign Whitepapers 
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

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Everything You Must Know About ColdFusion Variables - Data Type Category of Variables


    (Page 6 of 7 )

    ColdFusion, unlike others, does not associate variable names with types. In this sense, it is "type less." However, the data of a variable usually has a type, and this affects how ColdFusion evaluates an expression, or a function. ColdFusion carries out automatic data conversions while evaluating expressions and functions. We will consider data type conversions later. The category of data types in ColdFusion can be any from the following:

     

    Data Type Brief Description Examples
    Simple Type
    Integers These are whole numbers. Decimal point not allowed. 0, -100, 75
    Real Numbers Numbers that might include a decimal value. 0.001, 100.001, -87.5
    Strings Strings are a sequence of symbols, such as letters, numbers, and special characters arranged like a word but not necessarily meaningful. "Welcome", 'sbs@yahoo.com', '100X'
    Booleans True or false logic.
    • True can be expressed as Yes, 1, or any nonzero number.
    • False can take No or 0
    Date-Time Reference point in time.
    • Date
    • Time
    • Date and Time
    Complex Type
    Lists A number of entries in a string separated by a delimiting character. The default delimiter is a comma.
    • 1,2,3,4,5,6 is a list
    • Sun; Mon; Tue;Wed;Thur:Fri:Sat is also a list
    Arrays Stored data in a table structure accessible by an index or indices. See example
    Structures Another complex data type, members accessed by a 'key' and its 'value' See example
    Queries Results returned by a question posed to the database. SELECT query results from a database
    Binary Type
    Binary Raw data of an image GIF file, or a binary executable. For example, Notepad.exe, dog.gif
    Object Type
    Object Complex data and methods that work with data. COM, CORBA, and Java type created by <cfobject> tag

    Some data type category examples: Simple Type

    These include numbers, strings, etc. Here is an example file, SimpleCat.cfm which has a couple of different data types.

    <!--- This is an example of using Simple Type category--->
    <cfoutput>Simple Type Category<br/></cfoutput>
    <cfoutput><b>Next line, strg represents a string</b><br/></cfoutput>
    <cfset strg="Welcome">
    <cfoutput>
    #strg#
    </cfoutput><br/>
    <cfoutput><b>Next line, n represents a positive integer</b><br/></cfoutput>
    <cfset n=10 >
    <cfoutput>
    #n#
    </cfoutput><br/>
    <cfoutput><b>Next line, x represents a Boolean</b><br/></cfoutput>
    <cfset x=True>
    <cfoutput>
    #x#
    </cfoutput><br/>
    <cfoutput><b>Next line, t represents a Date/Time</b><br/></cfoutput>
    <cfset t=Now()>
    <cfoutput>
    #t#
    </cfoutput><br/>
    

    When this file is browsed with this address, http://localhost/TestingCF/SiampleCat.cfm we see the following displayed.

    Complex Type

    Arrays, Structures, XML documents, and so forth are the Complex Data Type Category in ColdFusion. Here are two examples, the first one being an array, (arrayed.cfm) and the next a structure, strut.cfm

    Array Variable
    <!---Defining an array variable with ArrayNew()--->
    <!---Usage of ArrayLen()--->
    <!---arrayed.cfm--->
    <!--- ArrayNew() defines an array colors--->
    <cfset colors=ArrayNew(1)>
    <!---colors[1]="red" sets the first element of array as 'red'--->
    <cfset colors[1]="Red">
    <cfset colors[2]="Green">
    <cfset colors[3]="Blue">
    <!---ArrayLen(colors) evaluates the number of array elements 
    in 'colors' array---> <cfset NoCol=ArrayLen(colors)> <cfoutput> #colors[1]# means danger<br/> </cfoutput> <cfoutput> Number of colors in the array=#NoCol# </cfoutput>

    Browser display of the above file appears as follows;

     

    Structure variable

     

    <!--Example of a simple structure--->
    <!---Usage of StructNew(), StructInsert()--->
    <!---A complex employee variable is created by suign StrctNew()--->
    <cfset employee=StructNew()>
    <!---Method to insert a structures member--->
    <cfset StructInsert(employee, "firstname", "Richard",1)>
    <cfset StructInsert(employee, "lastname", "Burton",1)>
    <cfoutput>
    <!---Accessing a memebr of the structure--->
    Full name of employee is:  #employee.firstname# #employee.lastname#  
    </cfoutput>
    

    A browser display of the above file appears as follows;

    Binary and Object type category of variables

    The examples for these will be deferred until we get used to more CFML tags, such as  <cffile>, <cfobject> and so on.

    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


    Iron Speed





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