Creating And Using Structures; Creating Structures; Adding Data Elements To Structures - MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual

Table of Contents

Advertisement

Creating and Using Structures

Creating and Using Structures

This section explains how to use the structure functions to create and use structures
in ColdFusion. The sample code in this section uses a structure called employee,
which is used to add new employees to a corporate information system.

Creating structures

You create structures by assigning a variable name to the structure with the
StructNew function:
<cfset mystructure=StructNew()>
For example, to create a structure named employee, use this syntax:
<cfset employee=StructNew()>
Now the structure exists and you can add data to it.

Adding data elements to structures

After you create a structure, you add key-value pairs to the structure using the
StructInsert
<cfset value=StructInsert(structure_name, key, value
The AllowOverwrite parameter is optional and can be either True or False. You can
use it to specify whether an existing key should be overwritten. The default is False.
When adding string values to a structure, enclose the string in quotation marks. For
example, to add a key, John, with a value, Sales, to an existing structure called
Departments, use this syntax:
<cfset value=StructInsert(Departments, "John", "Sales")>
The following example shows how to add content to a sample structure named
employee, building the content of the value fields dynamically using form variables:
<cfset rc=StructInsert(employee, "firstname", "#FORM.firstname#")>
<cfset rc=StructInsert(employee, "lastname", "#FORM.lastname#")>
<cfset rc=StructInsert(employee, "email", "#FORM.email#")>
<cfset rc=StructInsert(employee, "phone", "#FORM.phone#")>
<cfset rc=StructInsert(employee, "department", "#FORM.department#")>
function:
[, AllowOverwrite])>
127

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 5

Table of Contents