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

  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.
     
    Kevin Spencer, Oct 24, 2003
    #2
    1. Advertisements

  3. Marc Bishop

    Marc Bishop Guest

    Thanks Kevin,
    looking into a way of doing it with collections now.
     
    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.
     
    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 :)
     
    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.
     
    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 !
     
    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.
     
    Road Warrior, Nov 1, 2003
    #8
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.