User Guide
Working with Variables 15
Adding more variables to the application
Applications can use many different variables. For example, the calldept.cfm
application page can set and display values for department, city, and salary.
To modify the application:
1 Open the file calldept.cfm in ColdFusion Studio,.
2 Modify the code so that it appears as follows:
<html>
<head>
<title>Call Department</title><br>
</head>
<body>
<strong>Call Department</strong><br>
<!--- Set all variables --->
<cfset Department="Sales">
<cfset City="Boston">
<cfset Salary="110000">
<!--- Display results --->
<cfoutput>
Iād like to talk to someone in #Department# in #City# who earns at
least #Salary#.
</cfoutput>
</body>
</html>
3 Save the file.
<cfoutput>
Iād like to talk to someone in
#Department#.
</cfoutput>
ColdFusion replaces the variable
Department with its value. The HTML page
displays:
Iād like to talk to someone in Sales.
<cfoutput>
The department name spelled
backward is Reverse(Department).
</cfoutput>
ColdFusion sees Reverse(Department) as
text and displays it unchanged. The HTML
page displays:
The department name spelled backward is
Reverse(Department).
<cfoutput>
The department name spelled
backward is #Reverse(Department)#.
</cfoutput>
ColdFusion uses the Reverse function to
reverse the text in the Department variable
and displays the result. The pound signs tell
cfoutput to interpret Reverse as a
ColdFusion function. The
Reverse function
uses the Department variable name. The
HTML page displays:
The department name spelled backward is
selaS.
CFML code Results