>-----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
%>
|