Chapter 2: Writing Your First ColdFusion Application
13
Variables
A Web application page is different from a static Web page because it can publish data
dynamically. This involves creating, manipulating, and outputting variables.
A variable stores data that can be used in applications. As with other programming
languages, you’ll set variables in ColdFusion to store data that you want to access later.
And you’ll reference a range of variables to perform different types of application
processing.
There are a variety of variable types that you can create and reference in your
ColdFusion applications. Also, ColdFusion variables are typeless, which means that
you don’t need to define whether or not the variable value is numeric, text, or time-
date. See the CFML Language Reference for a complete list of variable types
The primary differences between variable types are where they exist, how long they
exist, and where their values are stored. These considerations are referred to as a
variable’s scope.
You will learn more about scope as needed throughout this book.
For example, you would store a user’s preferences in a variable in order to use that data
to customize the page that’s returned to the browser.
You don’t use pound signs when you create the variable. However, when you want to
display the value that a variable is set to, enclose the variable name in pound signs (#).
The following table illustrates the use of pound signs and variable names.
CFML Code
Results
<CFSET Department="Sales">
The variable named Department is created
and the value is set to Sales.
<CFOUTPUT>
I’d like to talk to someone in
Department.
</CFOUTPUT>
ColdFusion doesn’t treat Department as a
variable because it isn’t surrounded by
pound signs. The HTML page will display:
I’d like to talk to someone in Department.
<CFOUTPUT>
I’d like to talk to someone in
#Department#.
</CFOUTPUT>
ColdFusion replaces the variable Department
with its value. The HTML page will display:
I’d like to talk to someone in Sales.
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...