Delete Items from multidimensional array

C

Colin Steadman

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
 
C

Colin Steadman

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

%>
 

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

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top