Everything You Must Know About ColdFusion Variables
Understanding ColdFusion variables and logic is vital to being able to program in the language. In this tutorial, Jay's second covering ColdFusion, you will learn about the types of ColdFusion variables and how to use them.
Everything You Must Know About ColdFusion Variables - Data Type Category of Variables (Page 6 of 7 )
ColdFusion, unlike others, does not associate variable names with types. In this sense, it is "type less." However, the data of a variable usually has a type, and this affects how ColdFusion evaluates an expression, or a function. ColdFusion carries out automatic data conversions while evaluating expressions and functions. We will consider data type conversions later. The category of data types in ColdFusion can be any from the following:
These are whole numbers. Decimal point not allowed.
0, -100, 75
Numbers that might include a decimal value.
0.001, 100.001, -87.5
Strings are a sequence of symbols, such as letters, numbers, and special characters arranged like a word but not necessarily meaningful.
True can be expressed as Yes, 1, or any nonzero number.
False can take No or 0
Reference point in time.
Date and Time
A number of entries in a string separated by a delimiting character. The default delimiter is a comma.
1,2,3,4,5,6 is a list
Sun; Mon; Tue;Wed;Thur:Fri:Sat is also a list
Stored data in a table structure accessible by an index or indices.
Another complex data type, members accessed by a 'key' and its 'value'
Results returned by a question posed to the database.
SELECT query results from a database
Raw data of an image GIF file, or a binary executable.
For example, Notepad.exe, dog.gif
Complex data and methods that work with data.
COM, CORBA, and Java type created by <cfobject> tag
Some data type category examples: Simple Type
These include numbers, strings, etc. Here is an example file, SimpleCat.cfm which has a couple of different data types.
<!--- This is an example of using Simple Type category--->
<cfoutput>Simple Type Category<br/></cfoutput>
<cfoutput><b>Next line, strg represents a string</b><br/></cfoutput>
<cfoutput><b>Next line, n represents a positive integer</b><br/></cfoutput>
<cfset n=10 >
<cfoutput><b>Next line, x represents a Boolean</b><br/></cfoutput>
<cfoutput><b>Next line, t represents a Date/Time</b><br/></cfoutput>
When this file is browsed with this address, http://localhost/TestingCF/SiampleCat.cfm we see the following displayed.
Arrays, Structures, XML documents, and so forth are the Complex Data Type Category in ColdFusion. Here are two examples, the first one being an array, (arrayed.cfm) and the next a structure, strut.cfm
<!---Defining an array variable with ArrayNew()--->
<!---Usage of ArrayLen()--->
<!--- ArrayNew() defines an array colors--->
<!---colors="red" sets the first element of array as 'red'--->
<!---ArrayLen(colors) evaluates the number of array elements
in 'colors' array--->
#colors# means danger<br/>
Number of colors in the array=#NoCol#
Browser display of the above file appears as follows;
<!--Example of a simple structure--->
<!---Usage of StructNew(), StructInsert()--->
<!---A complex employee variable is created by suign StrctNew()--->
<!---Method to insert a structures member--->
<cfset StructInsert(employee, "firstname", "Richard",1)>
<cfset StructInsert(employee, "lastname", "Burton",1)>
<!---Accessing a memebr of the structure--->
Full name of employee is: #employee.firstname# #employee.lastname#
A browser display of the above file appears as follows;
Binary and Object type category of variables
The examples for these will be deferred until we get used to more CFML tags, such as <cffile>, <cfobject> and so on.