BTW: Your ArrayNew(5) would try to create a 5 dimension array which is not
legal in ColdFusion. You can only create 1, 2 or 3 dimension arrays. In the
ArrayNew() function, you specify the number of dimensions not the number of
elements. But the rest of your comments are on target.

Dave Cahall
Vice President, Professional Services
Digitaris Technologies, Inc.
Office: 972.690.4131 ext 116
Mobil: 214.914.9947


-----Original Message-----
From: Billy Cravens [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 17, 2001 10:31 AM
To: [EMAIL PROTECTED]
Subject: Re: isDefined Function


Josh,

I don't think that's what Ricardo's trying to get.  Your code basically 
determines if an array exists and if it has any length.  However, it's 
possible to create an array, but all elements do not exist:

<cfscript>
myArray = ArrayNew(5);
myArray[2] = "test1";
myArray[3] = "test2";
myArray[4] = "test3";
myArray[5] = "test4";
</cfscript>

Referencing myArray[1] at this point will throw an exception.

What I like to do is use ArraySet() to "initialize" the array:

<cfscript>
myArray = ArrayNew(5);
myArray = ArraySet(myArray,1,ArrayLen(myArray),"");
myArray[2] = "test1";
myArray[3] = "test2";
myArray[4] = "test3";
myArray[5] = "test4";
</cfscript>


To test for value, I use:
<cfif Len(myArray[1])> which will return false if no value has been 
assigned.  Additionally, you could use a different "placeholder" if 
zero-length strings are possible array values.

--
Billy Cravens, EDS
[EMAIL PROTECTED]



>From: Josh Meekhof <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: [EMAIL PROTECTED]
>Subject: Re: isDefined Function
>Date: Sun, 16 Sep 2001 13:02:00 -0500
>
>On Sat, Sep 15, 2001 at 09:50:07PM -0700, RICARDO SANOJA wrote:
> > Does anyone know how to validate an array element to see if exists.
> > This is what I am trying to do.  I get an error.
> >
> > <cfif isDefined("newWiz.deadlines[1]")>#newWiz.deadlines[1]#</cfif>
> >
> > The error:
> > Parameter 1 of function IsDefined which is now "newWiz.deadlines[1]" 
>must be
> > a syntactically valid variable name
> >
> >
> > The error occurred while processing an element with a general identifier

>of
> > (CFIF), occupying document position (78:4) to (78:42)
> >
> >
> >
> > Sincerely,
> > Ricardo Sanoja
>Ricardo,
>
>Let me give this a try.  It'll have to be done in a couple of seperate
>steps.
>
><cfscript>
>if (isDefined("newWiz.deadlines") and isArray(newWiz.deadlines)) {
>// here's the tricky part. CF doesn't force the programmer to insert
>// elements into any order. So, that's on you.
>   if ( ArrayLen(newWiz.deadlines)) {
>     /*
>        all your code that depends upon elements of the array go here
>     */
>   }
>}
></cfscript>
>
>
>Obviously some tweaking will have to be done in order to fit your
>circumstance, but something like this should fit your needs.
>--
>Josh Meekhof
>
>-------------------------------------------------------------------------
>This email server is running an evaluation copy of the MailShield anti-
>spam software. Please contact your email administrator if you have any
>questions about this message. MailShield product info: www.mailshield.com
>
>-----------------------------------------------
>To post, send email to [EMAIL PROTECTED]
>To subscribe / unsubscribe: http://www.dfwcfug.org


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


-------------------------------------------------------------------------
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info: www.mailshield.com

-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org

-------------------------------------------------------------------------
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info: www.mailshield.com

-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org

Reply via email to