Delete Items from multidimensional array

Discussion in 'ASP General' started by Colin Steadman, Oct 12, 2004.

  1. I have a multi-dimensional array that I want to delete
    items from. To do this I display a form and the user
    clicks some tick boxes.

    Then on the delete page I check which tick boxes were
    ticked, say 2,4,7 and 8 (or whatever) and then rebuild the
    array minus records 2,4,7 and 8 and so on.

    Sounds simple enough, but I'm having a real nightmare
    getting it to work. So my questions is how are others
    doing this, as my way is obviously very shoddy! I've been
    looking for examples on the internet, but I've not managed
    to find one!

    TIA,

    Colin
     
    Colin Steadman, Oct 12, 2004
    #1
    1. Advertising


  2. >-----Original Message-----
    >I have a multi-dimensional array that I want to delete
    >items from. To do this I display a form and the user
    >clicks some tick boxes.
    >
    >Then on the delete page I check which tick boxes were
    >ticked, say 2,4,7 and 8 (or whatever) and then rebuild

    the
    >array minus records 2,4,7 and 8 and so on.
    >
    >Sounds simple enough, but I'm having a real nightmare
    >getting it to work. So my questions is how are others
    >doing this, as my way is obviously very shoddy! I've

    been
    >looking for examples on the internet, but I've not

    managed
    >to find one!
    >
    >TIA,
    >
    >Colin
    >.
    >




    Ignore this, after spending most of yesterday balls this
    up. I've just got it working:

    <%Option Explicit%>
    <!-- #INCLUDE FILE="formatting.asp" -->
    <!-- #INCLUDE FILE="vb_functions.asp" -->

    <%

    beginPage

    '----------------------------------------------------------
    ------------------------------------------+
    'Declare variables
    '----------------------------------------------------------
    ------------------------------------------+

    Dim i
    Dim firstItem
    Dim deleteItem
    Dim my_preferences
    Dim lngUBound

    Dim newArray
    ReDim newArray(1,0)

    firstItem = True

    '----------------------------------------------------------
    ------------------------------------------+
    'Get list of deleted items and convert into array
    '----------------------------------------------------------
    ------------------------------------------+

    my_preferences = Session("my_preferences")

    '----------------------------------------------------------
    ------------------------------------------+
    'Get preferences array
    '----------------------------------------------------------
    ------------------------------------------+

    'Loop through array of preferences
    For i = LBound(my_preferences,2) To Ubound
    (my_preferences,2)

    deleteItem = deleteThisItem(i)

    'If we still want this preference, add it to the new
    array
    If Not deleteItem Then

    response.write "<br>ADD " & my_preferences(0,i) & " and
    (" & my_preferences(1,i) & ") to new array"

    'Determine the new upper bound of the rows within this
    array
    If firstItem Then
    lngUBound = 0
    firstItem = False
    Else
    lngUBound = UBound(newArray, 2) + 1
    End If

    'Re-demention the array to the size of the new
    upperbound
    ReDim Preserve newArray(UBound(newArray, 1), lngUBound)

    'Add the data
    newArray(0,lngUBound) = my_preferences(0,i)
    newArray(1,lngUBound) = my_preferences(1,i)
    Else
    response.write "<br>DONT add to new array"
    End If

    Next

    response.write "<br><br>"

    For i = LBOUND(newArray,2) to UBOUND(newArray,2)
    response.write "<br>"& newArray(0,i) & " (" & newArray
    (1,i) & ")"
    Next


    'Put new array into preferences sessions variable
    Erase my_preferences
    Session.Contents.Remove("my_preferences")
    Session("my_preferences") = newArray
    Erase newArray

    'Tidy Up
    Set i = Nothing
    Set firstItem = Nothing
    Set deleteItem = Nothing
    Set my_preferences = Nothing
    Set lngUBound = Nothing


    '----------------------------------------------------------
    ------------------------------------------+
    'Get preferences array
    '----------------------------------------------------------
    ------------------------------------------+

    Function deleteThisItem(itemVar)

    Dim i
    Dim deletionsArray

    'Get array of items we dont want
    deletionsArray = Split(Request.QueryString
    ("deleteset"),",")

    'Assume we want the item
    deleteThisItem = False

    'Confirm item not wanted
    For i = LBound(deletionsArray,1) To UBound
    (deletionsArray,1)
    If CInt(itemVar) = CInt(deletionsArray(i)) Then
    deleteThisItem = True
    Next

    Erase deletionsArray
    Set i = Nothing

    End Function

    Response.redirect("manage_preferences.asp")

    finishPage

    %>
     
    Colin Steadman, Oct 12, 2004
    #2
    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. Dave Bazell

    slice of multidimensional array

    Dave Bazell, Jul 23, 2003, in forum: Perl
    Replies:
    2
    Views:
    4,086
  2. epigram
    Replies:
    1
    Views:
    10,827
    =?Utf-8?B?c29jaWV0b3BpYS5uZXQ=?=
    Jul 16, 2005
  3. Ben
    Replies:
    8
    Views:
    12,650
    Eki Y. Baskoro
    Dec 18, 2003
  4. Huub
    Replies:
    6
    Views:
    612
  5. Guest

    Delete ASP Multidimensional Array

    Guest, Mar 23, 2006, in forum: ASP General
    Replies:
    10
    Views:
    368
    Bob Barrows [MVP]
    Mar 23, 2006
Loading...

Share This Page