Using functions on values
Usually, a function performs an operation on a value, and the value can include the value of a
variable. For example, to format the value of a variable that contains a value in dollars, the code to
write this statement might look like this:
#DollarFormat(price)#
The
DollarFormat
places, a thousands separator, and a dollar sign. The number signs (#) around the function
instruct ColdFusion to evaluate the content between the number signs and display the value.
Nesting functions
Functions can generate data, as well as act on data. Consider the following example:
#DateFormat(Now(), "mm/dd/yyyy")#
In this example, the
formats the date.
Variables
Variables let you store data in memory on the server. Variables always have a name and a value.
You can assign a value to a variable, or you can instruct ColdFusion to assign variable values based
on data that it retrieves from a data source, such as a database table.
Naming variables
You must use the following rules for naming ColdFusion variables:
•
Names are case-insensitive (uppercase, lowercase, or mixed case).
•
Names can contain only letters, numbers, and underscore characters.
•
Each name must begin with a letter.
•
Special characters (such as double-quotation marks ("), reserved names (such as functions and
tags), and spaces are not allowed.
Ways to use variables
You can use variables for the following purposes:
•
Store data collected from a form.
•
Store results of a calculation (such as the number of database records returned).
•
Use as input to a function.
Creating variables with the cfset tag
ColdFusion lets you create variables as you need them. You create the variable (name and value)
using the
cfset
<cfset variable_name = value>
function returns a value as a string and formats that value with two decimal
function generates the date, and then the
Now()
tag. This tag has the following syntax:
function
DateFormat
About CFML elements
21
Need help?
Do you have a question about the COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION MX and is the answer not in the manual?
Questions and answers