Solved

How do I delete an element from an array

Posted on 2009-05-17
7
414 Views
Last Modified: 2013-11-27
I have 2 arrays, FileList1 and FileList2. As I compare the 2, I want to delete any entries in FileList1 that are also in FileList2.

I found an answer at http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23721653.html but I get the error "RemoveAt is not a member of System.Array"

It seems to have worked for a previous questioner so why not for me?

I am using Visual Studio Express 2008, (Visual Basic).
Dim FileList1(count1) As String ' Count1 is determined by some previous code
            Dim FileList2(count2) As String ' Count2 is determined by some previous code
 
            ' Code to populate the arrays
 
           If FileList1.Count > FileList2.Count Then
                For i As Integer = FileList1.Count - 1 To 0 Step -1
                    For x As Integer = FileList2.Count - 1 To 0 Step -1
                        If FileList2(x).ToString = FileList1(i).ToString Then
                            FileList1.RemoveAt(i)
                            Exit For 
                        End If
                    Next
                Next
            End If

Open in new window

0
Comment
Question by:jindalee
7 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 24405894
Consider using an ArrayList instead of Array. Then you can use the RemoveAt method.

Wayne
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24406116
As Webtubbs said, Array is not resizable. You have to use arraylist to add or remove items dynamically.
0
 
LVL 22

Expert Comment

by:p_davis
ID: 24423639
the asker in the pointer actually says that he has 2 arraylists.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Author Comment

by:jindalee
ID: 24465806
OOPS. So it does :S
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 24467090
Mr.jindalee,

the link you provided has used arraylist.I think you are using arrays.Right?
0
 
LVL 1

Author Comment

by:jindalee
ID: 24600854
Haven't forgotten the question - I've been diverted to a higher priority task and haven't had the chance to try the suggestions. Will get back to it soon.
0
 
LVL 1

Author Closing Comment

by:jindalee
ID: 31582344
As soon as I changed from Array to ArrayList I was able to twek the code to do what I needed.

Thank you
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question