How do I delete and Item from and array

  • Thread starter Thread starter Marc Bishop
  • Start date Start date
M

Marc Bishop

Hi can anyone help?

I'm making a shopping cart and am stuck on removing an item from my array?

The array is made :



cArray(ITEM_NAME,cItem) = ProductName

cArray(ITEM_PRODUCTID,cItem) = ProductID

cArray(ITEM_SIZE,cItem) = Size

cArray(ITEM_PRICE,cItem) = ProductPrice

cArray(ITEM_QUANTITY,cItem) = Qty



Then the cart is added to a session.

My question is how do i remove an item from the middle of this array?



Any help at all would be much appreciated



Thanks

Mike
 
Removing an item from an array is not particularly easy, as you must make a
new array. You would probably be better off using a Collection than an
array. If you want to use an array, you would create a second array with a
length 1 less than the original, and assign each item that you don't want to
remove to the second array in a loop.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
Is there anything you need information about regarding using a Collection?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
Actually that would be great what was on my mind was using a Listbox and
just make is visible = false - not a good idea i think you'd agree - i
couldn't find any information apart from ASP(vbscript) collection.

thanks :)
 
I'm kind of confused now, since a Collection, like an Array, is a data
storage device in memory, and a ListBox is a UI element. The Common Language
Runtime has lots of different Collections you can use, as well as having the
ability to create your own strongly-typed Collections. A Collection is
similr to an Array, but has the capability of having items added and removed
from it easily, without having to create a new Collection. Rather than, as
in your example, using a multi-dimensional Array, what you need to do is to
create a Class or Structure that holds all of the data associated with a
single item in the Shopping Cart. Once you have done that, you simply create
an instance of the Class or Structure and add it to the Collection, using
the Add() method of the Collection. To remove it from the Collection, you
use the Remove() method of the Collection.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
Well for collections there is an excellent tutorial on that. Just visit any
catholic church on Sunday and watch how they do it. Amazing.
 
Back
Top