Home arrow ColdFusion arrow Page 6 - Everything You Must Know About ColdFusion Variables

Everything You Must Know About ColdFusion Variables

Understanding ColdFusion variables and logic is vital to being able to program in the language. In this tutorial, Jay's second covering ColdFusion, you will learn about the types of ColdFusion variables and how to use them.

Author Info:
By: Jayaram Krishnaswamy
Rating: 4 stars4 stars4 stars4 stars4 stars / 25
August 15, 2005
  1. · Everything You Must Know About ColdFusion Variables
  2. · Developing ColdFusion Content
  3. · Variable definition with CFSET tag
  4. · Variable by assigning statements in CFSCRIPT
  5. · Scope of a variable
  6. · Data Type Category of Variables
  7. · How do we name a variable?

print this article

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><b>Next line, n represents a positive integer</b><br/></cfoutput>
<cfset n=10 >
<cfoutput><b>Next line, x represents a Boolean</b><br/></cfoutput>
<cfset x=True>
<cfoutput><b>Next line, t represents a Date/Time</b><br/></cfoutput>
<cfset t=Now()>

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()--->
<!--- 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)>
<!---Accessing a memebr of the structure--->
Full name of employee is:  #employee.firstname# #employee.lastname#  

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.

blog comments powered by Disqus

- Adobe ColdFusion Just Got More RAD
- 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...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials