f-l-i-p

I am attempting to write some code that will do a compare and report if it finds missing or duplicated numbers from two arrays.

First array will be a control set of good numbers (ie 0-10) and the other array will be the test data that could have missing or duplicate number.

What I need to do is find and the errors but carry one after each error is fond until the end of the control array

Sounds quite simple and is possibly is, but I am having a few issues

Of course your help is more that appreciated.



Re: Visual Basic Language Compare two arrays

Eusebiu

If I understood the problem well... I think the solution is the following one...

int n = TestArray.Length; int[] myArray = new int [ n ];

for(int i = 0 ; i < n ; i++)

myArray[TestArray [ i ] ]++;

for(int i = 0 ; i < n ; i++)

{

if(myArray [ i ] == 0 )//number not found in test

Console.WriteLine("{ 0 } is not in the array", i);

if(myArray [ i ] >=2)//number duplicate

Console.WriteLine("{0} appears more than once", i);

}




Re: Visual Basic Language Compare two arrays

f-l-i-p

Not sure that is will work in vb2005

any pointers





Re: Visual Basic Language Compare two arrays

Bruno Yu - MSFT

Hi,

You can try to coonvert the C# code to VB.NET code like this:

Code Snippet

Dim n As Integer = TestArray.Length

Dim myArray(n) As Integer

Dim i As Integer

For i = 0 To n - 1

myArray(TestArray(i)) += 1

Next i

Dim i As Integer

For i = 0 To n - 1

If myArray(i) = 0 Then 'number not found in test

Console.WriteLine("{ 0 } is not in the array", i)

End If

If myArray(i) >= 2 Then 'number duplicate

Console.WriteLine("{0} appears more than once", i)

End If

Next i