Tim,

Arrays and structure are both good places to store stuff.  The
question is what type of stuff you want to store.

If you just need to store "something," an array can be a good way to
go.  If you need to store "something" and "stuff" (properties) about
it, a structure may be a good bet.

Example:  If I wanted to store the ISBN numbers of a bunch of books,
I'd use an array called "books" - books[1] would be the ISBN of the
first book, books[2] the second, and so on.

If I wanted to store a single book and "stuff" about it, I'd use a
structure - book.ISBN, book.author, book.title, etc.  Sure, you could
do this with an array: book[1] being title, book[2] being author,
etc., but then you have to remember that 1 = title, 2=author.  Think
of a structure as an array where instead of using numbers for each
element, you use a unique name.

More powerful still is an array of structures.  Going back to the
books example, you could have the books array with book[1] being a
structure, book[2] being a structure, etc., so that you have
book[1].title, book[2].title, book[3].title, and so on.

Lastly, you can have a structure of structures!   Say you developed
the app using the array of structures - then you suddenly need a
feature where you need to access the title of a book in the array by
knowing only its ISBN number.  You could create a structure called
"books", and inside put elements using their ISBN number as the name.
So you'd have books["222-442-5534"].title,
books["1232-442-5534"].title, and so on.

Whew.  If you'd like code samples for this, I can type those after lunch. :)


----- Original Message -----
From: Tim Laureska <[EMAIL PROTECTED]>
Date: Tue, 29 Jun 2004 10:35:21 -0400
Subject: RE: first time array
To: CF-Talk <[EMAIL PROTECTED]>

Tony... why are structures a better way to go than than arrays


-----Original Message-----

From: Tony Weeg [mailto:[EMAIL PROTECTED]

Sent: Tuesday, June 29, 2004 10:08 AM

To: CF-Talk

Subject: RE: first time array

tim, then there is this GREAT

thing called a structure, play with this one...

<cfset me = structNew()>

<cfset me.myFirstName = "Tim">

<cfset me.myLastName = "Laureska">

<cfset me.myCity = "Da' Bridge">

<P>

<cfdump var="#me#">

<P>

Hello world, my name is <cfoutput>#me.myFirstName# #me.myLastName# and i

live in #me.myCity#</cfoutput>

-----Original Message-----

From: Pascal Peters [mailto:[EMAIL PROTECTED]

Sent: Tuesday, June 29, 2004 10:06 AM

To: CF-Talk

Subject: RE: first time array

A 2D array requires 2 indexes. Change the first line to

<cfset cassettes_Array=ArrayNew(1)>

> -----Original Message-----

> From: Tim Laureska [mailto:[EMAIL PROTECTED]

> Sent: dinsdag 29 juni 2004 16:09

> To: CF-Talk

> Subject: RE: first time array

>

> Thomas... I changed what I had to this: (but now getting the

> error below, which is a bit cryptic).

>

> <cfset cassettes_Array=ArrayNew(2)>

> <cfset cassettes_Array[1]=form.issue>

> <cfset cassettes_Array[2]=form.title>

> <cfset cassettes_Array[3]=form.date1>

> <cfset cassettes_Array[4]=form.publication>

>

> Error Diagnostic Information

> An error occurred while evaluating the _expression_:

>  cassettes_Array[1]=form.issue

> Error near line 11, column 22.

> Cannot set element of indexed object

>

> The element at position 1 of the object cannot be set. May be

> the object is read-only. The object has elements in positions

> 1 through 0.

> The error is in dimension 1 of object "cassettes_Array".

>

>

> -----Original Message-----

> From: Thomas Chiverton [mailto:[EMAIL PROTECTED]

> Sent: Tuesday, June 29, 2004 9:42 AM

> To: CF-Talk

> Subject: Re: first time array

>

> On Tuesday 29 Jun 2004 14:42 pm, Tim Laureska wrote:

> > <cfset cassettes_Array=ArrayNew(2)>

> > <cfset cassettes_Array[ArrayLen(cassettes_Array)+1][1]=#form.issue#>

> > <cfset cassettes_Array[ArrayLen(cassettes_Array)+1][2]=#form.title#>

> > <cfset cassettes_Array[ArrayLen(cassettes_Array)+1][3]=#form.date1#>

> > <cfset

> > cassettes_Array[ArrayLen(cassettes_Array)+1][4]=#form.publication#>

>

> That should be

> cfset cassettes_Array[1]=form.issue

> cfset cassettes_Array[2]=form.title

> cfset cassettes_Array[3]=form.date1

> to match your cfloop.

>

> cfdump var="#cassettes_Array#" is useful for figuring out

> what you've just built when constructing nested structures.

> --

> Tom Chiverton

> Advanced ColdFusion Programmer

>

> Tel: +44(0)1749 834997

> email: [EMAIL PROTECTED]

> BlueFinger Limited

> Underwood Business Park

> Wookey Hole Road, WELLS. BA5 1AF

> Tel: +44 (0)1749 834900

> Fax: +44 (0)1749 834901

> web: www.bluefinger.com

> Company Reg No: 4209395 Registered Office: 2 Temple Back

> East, Temple Quay, BRISTOL. BS1 6EG.

> *** This E-mail contains confidential information for the

> addressee only. If you are not the intended recipient, please

> notify us immediately. You should not use, disclose,

> distribute or copy this communication if received in error.

> No binding contract will result from this e-mail until such

> time as a written document is signed on behalf of the

> company. BlueFinger Limited cannot accept responsibility for

> the completeness or accuracy of this message as it has been

> transmitted over public networks.***

>

>

>

>________________________________
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to