By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,251 Members | 2,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,251 IT Pros & Developers. It's quick & easy.

Delete Items from multidimensional array

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
-----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 thearray 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 beenlooking for examples on the internet, but I've not managedto 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

%>

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.