By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,053 Members | 976 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,053 IT Pros & Developers. It's quick & easy.

How do I delete and Item from and array

P: n/a
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

Nov 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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.

"Marc Bishop" <no******************@hotmail.com> wrote in message
news:KU*************@news-binary.blueyonder.co.uk...
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

Nov 17 '05 #2

P: n/a
Thanks Kevin,
looking into a way of doing it with collections now.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
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.

"Marc Bishop" <no******************@hotmail.com> wrote in message
news:KU*************@news-binary.blueyonder.co.uk...
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


Nov 17 '05 #3

P: n/a
Well for collections there is an excellent tutorial on that. Just visit any
catholic church on Sunday and watch how they do it. Amazing.
"Marc Bishop" <no******************@hotmail.com> wrote in message
news:G4************@news-binary.blueyonder.co.uk...
Thanks Kevin,
looking into a way of doing it with collections now.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
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.

"Marc Bishop" <no******************@hotmail.com> wrote in message
news:KU*************@news-binary.blueyonder.co.uk...
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



Nov 17 '05 #4

P: n/a
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.

"Marc Bishop" <no******************@hotmail.com> wrote in message
news:G4************@news-binary.blueyonder.co.uk...
Thanks Kevin,
looking into a way of doing it with collections now.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
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.

"Marc Bishop" <no******************@hotmail.com> wrote in message
news:KU*************@news-binary.blueyonder.co.uk...
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



Nov 17 '05 #5

P: n/a
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 :)
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:uY**************@tk2msftngp13.phx.gbl...
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.

"Marc Bishop" <no******************@hotmail.com> wrote in message
news:G4************@news-binary.blueyonder.co.uk...
Thanks Kevin,
looking into a way of doing it with collections now.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
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.

"Marc Bishop" <no******************@hotmail.com> wrote in message
news:KU*************@news-binary.blueyonder.co.uk...
> 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
>
>
>



Nov 17 '05 #6

P: n/a
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.

"Marc Bishop" <no******************@hotmail.com> wrote in message
news:5r***********@news-binary.blueyonder.co.uk...
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 :)
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:uY**************@tk2msftngp13.phx.gbl...
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.

"Marc Bishop" <no******************@hotmail.com> wrote in message
news:G4************@news-binary.blueyonder.co.uk...
Thanks Kevin,
looking into a way of doing it with collections now.
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
> 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.
>
> "Marc Bishop" <no******************@hotmail.com> wrote in message
> news:KU*************@news-binary.blueyonder.co.uk...
> > 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
> >
> >
> >
>
>



Nov 17 '05 #7

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

thanks for your help !

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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.

"Marc Bishop" <no******************@hotmail.com> wrote in message
news:5r***********@news-binary.blueyonder.co.uk...
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 :)
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:uY**************@tk2msftngp13.phx.gbl...
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.

"Marc Bishop" <no******************@hotmail.com> wrote in message
news:G4************@news-binary.blueyonder.co.uk...
> Thanks Kevin,
> looking into a way of doing it with collections now.
>
>
> "Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
> news:Oo**************@tk2msftngp13.phx.gbl...
> > 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.
> >
> > "Marc Bishop" <no******************@hotmail.com> wrote in message
> > news:KU*************@news-binary.blueyonder.co.uk...
> > > 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
> > >
> > >
> > >
> >
> >
>
>



Nov 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.