473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Delete Items from multidimensional array

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
1 3307
-----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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Golf Nut | last post by:
I am finding that altering and affecting values in elements in multidimensional arrays is a huge pain in the ass. I cannot seem to find a consistent way to assign values to arrays. Foreach would...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
1
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a...
10
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
1
by: Chuy08 | last post by:
If I have a multidimensional array like the following: Array $records =Array 0 = 30 year, 6.0; 1 = 30 year, 6.0; 2 = Pay Option, 1.0; 3 = Pay Option, 1.0; How could I flatten this to...
5
by: LittleCake | last post by:
Hi All, I have a multidimensional array where each sub-array contains just two entries, which indicates a relationship between those two entries. for example the first sub-array: =Array ( =30...
4
Jezternz
by: Jezternz | last post by:
First of all I am open to any suggestions and advice. If a javscript multidimensional array is a bad way to do this please say so. I considered XML but I wondered if this would be a bad idea as it...
12
by: filippo nanni | last post by:
Hello everybody, my question is this: I have two multidimensional arrays and I have to create a third one (for later use) from comparing these two. Here is my example code: //BEGIN CODE var...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.