How do I delete and Item from and array

Discussion in 'ASP .Net' started by Marc Bishop, Oct 24, 2003.

  1. Marc Bishop

    Marc Bishop Guest

    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
    Marc Bishop, Oct 24, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:KUcmb.44$...
    > 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
    >
    >
    >
    Kevin Spencer, Oct 24, 2003
    #2
    1. Advertising

  3. Marc Bishop

    Marc Bishop Guest

    Thanks Kevin,
    looking into a way of doing it with collections now.


    "Kevin Spencer" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:KUcmb.44$...
    > > 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
    > >
    > >
    > >

    >
    >
    Marc Bishop, Oct 24, 2003
    #3
  4. 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" <> wrote in message
    news:G4fmb.13$...
    > Thanks Kevin,
    > looking into a way of doing it with collections now.
    >
    >
    > "Kevin Spencer" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > news:KUcmb.44$...
    > > > 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
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Kevin Spencer, Oct 24, 2003
    #4
  5. Marc Bishop

    Marc Bishop Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:G4fmb.13$...
    > > Thanks Kevin,
    > > looking into a way of doing it with collections now.
    > >
    > >
    > > "Kevin Spencer" <> wrote in message
    > > news:...
    > > > 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" <> wrote in message
    > > > news:KUcmb.44$...
    > > > > 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
    > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Marc Bishop, Oct 24, 2003
    #5
  6. 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" <> wrote in message
    news:5rgmb.1$...
    > 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" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > news:G4fmb.13$...
    > > > Thanks Kevin,
    > > > looking into a way of doing it with collections now.
    > > >
    > > >
    > > > "Kevin Spencer" <> wrote in message
    > > > news:...
    > > > > 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" <> wrote in message
    > > > > news:KUcmb.44$...
    > > > > > 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
    > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Kevin Spencer, Oct 24, 2003
    #6
  7. Marc Bishop

    Marc Bishop Guest

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

    thanks for your help !



    "Kevin Spencer" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:5rgmb.1$...
    > > 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" <> wrote in message
    > > news:...
    > > > 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" <> wrote in message
    > > > news:G4fmb.13$...
    > > > > Thanks Kevin,
    > > > > looking into a way of doing it with collections now.
    > > > >
    > > > >
    > > > > "Kevin Spencer" <> wrote in message
    > > > > news:...
    > > > > > 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" <> wrote in message
    > > > > > news:KUcmb.44$...
    > > > > > > 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
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Marc Bishop, Oct 25, 2003
    #7
  8. Marc Bishop

    Road Warrior Guest

    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" <> wrote in message
    news:G4fmb.13$...
    > Thanks Kevin,
    > looking into a way of doing it with collections now.
    >
    >
    > "Kevin Spencer" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > news:KUcmb.44$...
    > > > 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
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Road Warrior, Nov 1, 2003
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    616
  2. root

    item[LENGTH] vs. *item and malloc()

    root, Aug 21, 2003, in forum: C Programming
    Replies:
    2
    Views:
    386
    Eric Sosman
    Aug 21, 2003
  3. Ratko
    Replies:
    7
    Views:
    288
    Reedick, Andrew
    Jul 17, 2008
  4. Namor
    Replies:
    0
    Views:
    259
    Namor
    Jan 19, 2006
  5. Chris Kalaboukis

    Delete Item In Array If Conditions Met

    Chris Kalaboukis, Feb 11, 2010, in forum: Ruby
    Replies:
    6
    Views:
    153
    Albert Schlef
    Feb 12, 2010
Loading...

Share This Page