hi everyone. I have two array, array1 is two dimension and array2 is one dimension. I want to compare each number in array1 to array2 and if the number is not existing in array2 i want to add this number to array2. I am using vb.net2010. please help me

Recommended Answers

Make two nested loops, 1st loop to go through Array1 and 2nd loop to go through Array2 for comparing.

For i as Integer = 0 to Array1.GetUpperBound(0)
    Dim comp As Boolean = False

    For j as integer = 0 to Array2.GetUpperBound(0)
        If Array2(j)=Array1(i) Then
            comp = True
            Exit For …
Jump to Post

All 2 Replies

Make two nested loops, 1st loop to go through Array1 and 2nd loop to go through Array2 for comparing.

For i as Integer = 0 to Array1.GetUpperBound(0)
    Dim comp As Boolean = False

    For j as integer = 0 to Array2.GetUpperBound(0)
        If Array2(j)=Array1(i) Then
            comp = True
            Exit For
        End If
    Next

    If comp then
        Redim Preserve Array2(Array2.GetUpperBound(0) + 1)
        Array2(Array2.GetUpperBound(0)) = Array1(i)
    End If
Next

Hope it can help you

thank you very much for answer me but i solve the problem and my solve is exactly your solve and it work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.