Solved

How do I delete an element from an array

Posted on 2009-05-17
7
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…

730 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