Solved

How do I delete an element from an array

Posted on 2009-05-17
7
412 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now