How do I delete and Item from and array

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
 
K

Kevin Spencer

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.
 
K

Kevin Spencer

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.
 
M

Marc Bishop

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 :)
 
K

Kevin Spencer

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.
 
M

Marc Bishop

Sorry Kevin,
yes i understand now,
i think i'll pick this up tomorrow with a clear head :)

thanks for your help !
 
R

Road Warrior

Well for collections there is an excellent tutorial on that. Just visit any
catholic church on Sunday and watch how they do it. Amazing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top