Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ArrayDeleteAt

Status
Not open for further replies.

khurram

IS-IT--Management
Jan 10, 2001
95
CA
Using the ArrayDeleteAt function is causing some grief.

I have a shopping cart based on a 2D array. If I have two or more items in the shopping cart and try to delete the first item, I get an error. But deleting 2nd, 3rd, etc items first causes no problems.

I am not sure if the array needs to be resized or something like that.

Here's the code I have for both update and deleting the cart.

<CFSET #NumberOfItems# = 0>
<CFLOOP index=&quot;NewQty&quot; from=&quot;1&quot; to=&quot;#ListLen(FORM.Qty)#&quot;>
<CFSET #Session.sShoppingCart[NewQty][2]# = #ListGetAt(FORM.Qty, NewQty)#>
<CFSET #NumberOfItems# = #NumberOfItems# + 1>
</CFLOOP>
<CFLOOP index=&quot;NewQty&quot; from=&quot;1&quot; to=&quot;#arrayLen(Session.sShoppingCart)#&quot;>
<CFIF #Session.sShoppingCart[NewQty][2]# EQ 0>
<CFSET #DeleteItem# = #arrayDeleteAt(Session.sShoppingCart, NewQty)#>
<CFSET #NumberOfItems# = #NumberOfItems# - 1>
</CFIF>
</CFLOOP>
<CFSET #ShoppingCartResize# = #arrayResize(Session.sShoppingCart, NumberOfItems)#>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top