472,993 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Delete Element from array

Hi,

I created such procedure for deleting element from my dynamic array
because I could not find such possibility from .Net .
Private aintABC() As Int32

'' Initialization somewhere in another procedure

Private Sub DeleteFromArray(ByVal intIndex As Integer)
Dim i As Integer
For i = intIndex + 1 To aintABC.Length - 1
aintABC(i - 1) = aintABC(i)
Next
ReDim Preserve aintABC(aintABC.Length - 2)
End Sub
Maybe somebody know how I can do it without iteration or .Net does not
have any standart decision.

Thanks
Nov 20 '05 #1
7 9904
* y1***@yahoo.com (Mike) scripsit:
I created such procedure for deleting element from my dynamic array
because I could not find such possibility from .Net .


Use an 'ArrayList' instead.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
You could do it with CopyTo method.

Bismark
"Mike" <y1***@yahoo.com> a écrit dans le message de
news:93**************************@posting.google.c om...
Hi,

I created such procedure for deleting element from my dynamic array
because I could not find such possibility from .Net .
Private aintABC() As Int32

'' Initialization somewhere in another procedure

Private Sub DeleteFromArray(ByVal intIndex As Integer)
Dim i As Integer
For i = intIndex + 1 To aintABC.Length - 1
aintABC(i - 1) = aintABC(i)
Next
ReDim Preserve aintABC(aintABC.Length - 2)
End Sub
Maybe somebody know how I can do it without iteration or .Net does not
have any standart decision.

Thanks

Nov 20 '05 #3
You don't know the use of the table ... So you can't give this advice !!!
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> a écrit dans le
message de news:c6************@ID-208219.news.uni-berlin.de...
* y1***@yahoo.com (Mike) scripsit:
I created such procedure for deleting element from my dynamic array
because I could not find such possibility from .Net .


Use an 'ArrayList' instead.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #4
* "Bismark Prods" <tr*******@vtxnet.ch> scripsit:
You don't know the use of the table ... So you can't give this advice !!!


?!?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
Mike,
As the others have suggested.

If boxing of value types is a concern, for an array of Integer (and other
value types) I would consider using Array.Copy to copy the elements before &
after the element that I was deleting.

Something like:
Private Shared Sub DeleteFromArray(ByRef aintABC() As Integer, ByVal
intIndex As Integer)
Dim result(aintABC.Length - 2) As Integer
Array.Copy(aintABC, 0, result, 0, intIndex)
Array.Copy(aintABC, intIndex + 1, result, intIndex,
aintABC.Length - intIndex - 1)
aintABC = result
End Sub

For an array of reference types or if boxing is not an issue. I would use an
ArrayList or a class derived from CollectionBase. More then likely I would
use an ArrayList, until performance was proven to be an issue via profiling.
When Whidbey (VS.NET 2005) ships we will have a generic ArrayList like class
where we will be able to delete from the middle of a collection of Integers,
without the expense of boxing the elements...

Hope this helps
Jay
"Mike" <y1***@yahoo.com> wrote in message
news:93**************************@posting.google.c om...
Hi,

I created such procedure for deleting element from my dynamic array
because I could not find such possibility from .Net .
Private aintABC() As Int32

'' Initialization somewhere in another procedure

Private Sub DeleteFromArray(ByVal intIndex As Integer)
Dim i As Integer
For i = intIndex + 1 To aintABC.Length - 1
aintABC(i - 1) = aintABC(i)
Next
ReDim Preserve aintABC(aintABC.Length - 2)
End Sub
Maybe somebody know how I can do it without iteration or .Net does not
have any standart decision.

Thanks

Nov 20 '05 #6
I would gently remarks that : This is not ever possible to use an ArrayList
at the place of a Table. It depends the use of.

Bismark
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> a écrit dans le
message de news:c6************@ID-208219.news.uni-berlin.de...
* "Bismark Prods" <tr*******@vtxnet.ch> scripsit:
You don't know the use of the table ... So you can't give this advice
!!!
?!?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #7
* "Bismark Prods" <tr*******@vtxnet.ch> scripsit:
I would gently remarks that : This is not ever possible to use an ArrayList
at the place of a Table. It depends the use of.


I agree, but if the OP is talking about a dynamic array, an arraylist is
more likely the better solution.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Westcoast Sheri | last post by:
Any way to do a simple delete from array? In other words, what would be the *easiest* (and fastest php runtime) way to delete "banana" from the following array: $my_array = array( "apple",...
4
by: Shea Martin | last post by:
Which of the following do I use delete instead of just delete. //1.) // not sure about this one, as char is of size 1 char *str = new char; //2.) //not sure about this one, as it is a...
3
by: Brian Underhill via DotNetMonster.com | last post by:
I am trying to delete an element from an array. I have an array of 52 elements and I want to search for an element and delete it. Therefore, making it an array of 51 elements. is it just ...
6
by: flash | last post by:
write a program that manipulates arrays of integers. The main program should call three functions: Insert, Delete, and Search. The Insert function should call a function Sort that sorts the array. ...
7
by: JH Programmer | last post by:
Hi, is there any ways that allow us to delete an element in between? say int_val: 1 int_val: 2 int_val: 3
29
by: Jon Slaughter | last post by:
Is it safe to remove elements from an array that foreach is working on? (normally this is not the case but not sure in php) If so is there an efficient way to handle it? (I could add the indexes to...
7
by: =?utf-8?B?5YiY5piK?= | last post by:
Hi, folks, Is it possible to delete an element from a sorted array with O(1) time? Best regards
29
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I remembered delete is implemented through operator overloading, but I am not quite clear. Could anyone recommend some links about how delete is implemented so that I can...
3
by: vaibhavkanwal | last post by:
Hi, i am trying to initialize a dynamic array and use this array to conduct linear search. I know about new and delete but as a pointer can be incremented by the sizeof its dataype, i wanted to...
12
by: subramanian100in | last post by:
Suppose class Base { public: virtual ~Test() { ... } // ... }; class Derived : public Base
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.