Then you'll need to do <cfset form.remove=ListSort(form.remove, "numeric", > "desc")>
before your loop --- [EMAIL PROTECTED] wrote: > That's what I was trying to do with the ListSort() > function. > > > H. > > > -----Original Message----- > From: Hanz Zarcovic > [mailto:[EMAIL PROTECTED]] > Sent: Sunday, September 30, 2001 1:46 PM > To: CF-Talk > Subject: Re: Using CFLoop to delete from an Array > > > I think what you are describing is a common problem. > The problem is that when you start your loop the > array is 7 elements long, > you delete the first and the array is now only 6 > long , but your loop still > thinks the array has 7 items. > > The trick is to loop in reverse, from the end of > your array *down to* the > first item. This way you are never trying to delete > an item that dosen't > exist. > > Hope this helps. > -eric > > ----- Original Message ----- > From: <[EMAIL PROTECTED]> > To: "CF-Talk" <[EMAIL PROTECTED]> > Sent: Sunday, September 30, 2001 4:08 PM > Subject: Using CFLoop to delete from an Array > > > > I have a form that will allow users to randomly > select items to remove > from > > a form. All of the items in the form are an Array > of Structures. > > > > By clicking "remove" the number of the array > position is identified. More > > than remove checkbox can be checked. They can be > checked in any order. > > > > Currently, if only one item is check and the > submit button is clicked, the > > item is removed from the Array without a problem. > > > > The problem comes in when there is an attempt to > remove two or more items > > simultaneously. > > > > An error such as this is displayed: > > > > "ArrayDeleteAt(Array, Position): Cannot delete > element at position 7. > > The array has only 6 elements. > > > > "The error occurred while evaluating the > expression: > > #ArrayDeleteAt(session.cart, i)#" > > > > I've tried various ways to get this to work, so as > sorting the array > (which > > didn't work because the first element isn't a > simple variable), and trying > > to get the cfloop to remove the bottom item before > the top item. That > isn't > > working. > > > > Below is my current code, but my question is ... > how can I loop through > the > > array and remove all of the items I want? > > > > Current Code: > > > > > > <cfoutput>#ListSort(form.remove, "numeric", > "desc")#</cfoutput> > > > > <cfloop index="i" list="#form.remove#"> > > > > <cfoutput> > > #ArrayDeleteAt(session.cart, i)# > > #ArrayResize(session.cart, 1)# > > </cfoutput> > > > > </cfloop> > > ===== I-Lin Kuo Macromedia CF5 Advanced Developer Sun Certified Java 2 Programmer ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/[email protected]/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

