Functions


Functions return manipulated values for use in, for example, expressions. The functions do not change the data they are acting on; rather, they produce a result or return a value for output.

ColdFusion functions take the form FunctionName(argument). The argument may be nothing, like when you're using the function Now(), which returns the current date and time.

For a simple example, consider this assignment:

 <cfset Convert=UCase("hello")> 

The function used here is UCase(), which converts a string into all uppercase characters. The argument is the string "hello". The function does its work, and the assignment statement stores the string "HELLO" into the local variable Convert.

NOTE

#s can sometimes be confusing when you're using functions with ColdFusion variables. The proper way to use #s with a function and variable is as follows:

 #DateFormat(SellDate)# 

not:

 #DateFormat(#SellDate#)# 


Nested Functions

Functions can also be nested. This means the argument of a function can be another function itself. A very common example of nesting is using the DateFormat() function with the Now() function, as follows:

 DateFormat(Now()) 

Functions with Masks

Some functions also have another option called a mask. Functions that do formatting often have masks so that they can be tailored to an individual developer's needs. Again, consider the DateFormat() function. Say you want to change the default format to a date in the form mm/dd/yy. You do so as follows:

 DateFormat(Now(),"mm/dd/yy") 

The mask appears in quotation marks, separated from the argument by a comma.



Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net