
38
DEVELOPING
COLDFUSION 9 APPLICATIONS
The CFML Programming Language
Las
t
upda
te
d 8/5/2010
•
_date
•
_time
•
_eurodate
Because ColdFusion is not case-sensitive, all of the following are reserved words: IS, Is, iS, and is.
CFScript
CFScript
is a language within a language. CFScript is a scripting language that is similar to JavaScript but is simpler to
use. Also, unlike JavaScript, CFScript only runs on the ColdFusion server; it does not run on the client system. A
CFScript script can use all ColdFusion functions and all ColdFusion variables that are available in the script’s scope.
CFScript provides a compact and efficient way to write ColdFusion logic. Typical uses of CFScript include:
•
Simplifying and speeding variable setting
•
Building compact flow control structures
•
Encapsulating business logic in user-defined functions
The following sample script populates an array and locates the first array entry that starts with the word “key”. It shows
several of the elements of CFScript, including setting variables, loop structures, script code blocks, and function calls.
Also, the code uses a
cfoutput
tag to display its results. Although you can use CFScript for output, the
cfoutput
tag
is often easier to use.
<cfscript>
strings = ArrayNew(1);
strings[1]="the";
strings[2]="key to our";
strings[4]="idea";
for( i=1 ; i LE 4 ; i = i+1 )
{
if(Find("key",strings[i],1))
break; }
</cfscript>
<cfoutput>Entry #i# starts with "key"</cfoutput><br>
You use CFScript to create user-defined functions.
For more information on CFScript, see “
Extending ColdFusion Pages with CFML Scripting
” on page 106. For more
information on user-defined functions, see “
Writing and Calling User-Defined Functions
” on page 153.
Using ColdFusion Variables
Adobe ColdFusion variables are the most frequently used operands in ColdFusion expressions. Variable values can be
set and reset, and can be passed as attributes to CFML tags. Variables can be passed as parameters to functions, and
can replace most constants.
To create and use ColdFusion variables, you should know the following:
•
How variables can represent different types of data
•
How the data types get converted
•
How variables exist in different scopes
•
How scopes are used