Compare Two Listbox and send difference or similary in Textbox [closed]












0















I've restored the code and I need your help again. I created 2 Listbox boxes, I entered the data, and now I want to compare the 2 Listboxes and show the differences and similarities in another textbox. Everything I tried does not work at all, it just does not want it.
We have the following: And how can this be done on the Listbox line, ie Item (1,2,3,4). if it's possible. Because I will add more data to the listbox, which I want to compare with the other Listbox. Or simpler, how can I compare to the 2nd item on the listbox?
Example:
Listbox1.Items (1) = 1,2,3,4,5
ListBox1.Items (2) = 1,3,4,5,6



Listbox1.Items - with the following item: 1,3,5,11
Listbox2.Items - with the following item - 2,3,6,11


In Textbox1.text - you want to display the similarities and differences in Textbox2.text, for example the number that exists in Listbox1, and in Listbox2, is the number 3 and the number 11.
Then the differences: 1.5,6 in Textbox2.text
I realized it was much easier in the Listbox to do these things, so I hope you help me.



The intersection is easier in the listbox so I hope you help me because there is absolutely no code found worked, it's not good, it just does not show me the differences, or the similarities.










share|improve this question















closed as off-topic by Gábor Bakos, Blackwood, Jimi, Stedy, David Wilson Jan 2 at 16:53


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Gábor Bakos, Blackwood, Jimi, Stedy, David Wilson

If this question can be reworded to fit the rules in the help center, please edit the question.

















  • Hi and welcome to Stack Overflow. Its really important to ask questions properly here. Have a look at How to Ask and Minimal, Complete, and Verifiable example. This site is for questions regarding specific issues with existing code. As it stands, your question is off-topic because you don't explain what behaviour you're getting and what errors you get and on what line they occur. Don't let negative votes or votes to close put you off though. Thanks

    – David Wilson
    Jan 2 at 16:53
















0















I've restored the code and I need your help again. I created 2 Listbox boxes, I entered the data, and now I want to compare the 2 Listboxes and show the differences and similarities in another textbox. Everything I tried does not work at all, it just does not want it.
We have the following: And how can this be done on the Listbox line, ie Item (1,2,3,4). if it's possible. Because I will add more data to the listbox, which I want to compare with the other Listbox. Or simpler, how can I compare to the 2nd item on the listbox?
Example:
Listbox1.Items (1) = 1,2,3,4,5
ListBox1.Items (2) = 1,3,4,5,6



Listbox1.Items - with the following item: 1,3,5,11
Listbox2.Items - with the following item - 2,3,6,11


In Textbox1.text - you want to display the similarities and differences in Textbox2.text, for example the number that exists in Listbox1, and in Listbox2, is the number 3 and the number 11.
Then the differences: 1.5,6 in Textbox2.text
I realized it was much easier in the Listbox to do these things, so I hope you help me.



The intersection is easier in the listbox so I hope you help me because there is absolutely no code found worked, it's not good, it just does not show me the differences, or the similarities.










share|improve this question















closed as off-topic by Gábor Bakos, Blackwood, Jimi, Stedy, David Wilson Jan 2 at 16:53


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Gábor Bakos, Blackwood, Jimi, Stedy, David Wilson

If this question can be reworded to fit the rules in the help center, please edit the question.

















  • Hi and welcome to Stack Overflow. Its really important to ask questions properly here. Have a look at How to Ask and Minimal, Complete, and Verifiable example. This site is for questions regarding specific issues with existing code. As it stands, your question is off-topic because you don't explain what behaviour you're getting and what errors you get and on what line they occur. Don't let negative votes or votes to close put you off though. Thanks

    – David Wilson
    Jan 2 at 16:53














0












0








0








I've restored the code and I need your help again. I created 2 Listbox boxes, I entered the data, and now I want to compare the 2 Listboxes and show the differences and similarities in another textbox. Everything I tried does not work at all, it just does not want it.
We have the following: And how can this be done on the Listbox line, ie Item (1,2,3,4). if it's possible. Because I will add more data to the listbox, which I want to compare with the other Listbox. Or simpler, how can I compare to the 2nd item on the listbox?
Example:
Listbox1.Items (1) = 1,2,3,4,5
ListBox1.Items (2) = 1,3,4,5,6



Listbox1.Items - with the following item: 1,3,5,11
Listbox2.Items - with the following item - 2,3,6,11


In Textbox1.text - you want to display the similarities and differences in Textbox2.text, for example the number that exists in Listbox1, and in Listbox2, is the number 3 and the number 11.
Then the differences: 1.5,6 in Textbox2.text
I realized it was much easier in the Listbox to do these things, so I hope you help me.



The intersection is easier in the listbox so I hope you help me because there is absolutely no code found worked, it's not good, it just does not show me the differences, or the similarities.










share|improve this question
















I've restored the code and I need your help again. I created 2 Listbox boxes, I entered the data, and now I want to compare the 2 Listboxes and show the differences and similarities in another textbox. Everything I tried does not work at all, it just does not want it.
We have the following: And how can this be done on the Listbox line, ie Item (1,2,3,4). if it's possible. Because I will add more data to the listbox, which I want to compare with the other Listbox. Or simpler, how can I compare to the 2nd item on the listbox?
Example:
Listbox1.Items (1) = 1,2,3,4,5
ListBox1.Items (2) = 1,3,4,5,6



Listbox1.Items - with the following item: 1,3,5,11
Listbox2.Items - with the following item - 2,3,6,11


In Textbox1.text - you want to display the similarities and differences in Textbox2.text, for example the number that exists in Listbox1, and in Listbox2, is the number 3 and the number 11.
Then the differences: 1.5,6 in Textbox2.text
I realized it was much easier in the Listbox to do these things, so I hope you help me.



The intersection is easier in the listbox so I hope you help me because there is absolutely no code found worked, it's not good, it just does not show me the differences, or the similarities.







vb.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 31 '18 at 10:58







Aji Pangestu

















asked Dec 31 '18 at 10:52









Aji PangestuAji Pangestu

44




44




closed as off-topic by Gábor Bakos, Blackwood, Jimi, Stedy, David Wilson Jan 2 at 16:53


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Gábor Bakos, Blackwood, Jimi, Stedy, David Wilson

If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Gábor Bakos, Blackwood, Jimi, Stedy, David Wilson Jan 2 at 16:53


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Gábor Bakos, Blackwood, Jimi, Stedy, David Wilson

If this question can be reworded to fit the rules in the help center, please edit the question.













  • Hi and welcome to Stack Overflow. Its really important to ask questions properly here. Have a look at How to Ask and Minimal, Complete, and Verifiable example. This site is for questions regarding specific issues with existing code. As it stands, your question is off-topic because you don't explain what behaviour you're getting and what errors you get and on what line they occur. Don't let negative votes or votes to close put you off though. Thanks

    – David Wilson
    Jan 2 at 16:53



















  • Hi and welcome to Stack Overflow. Its really important to ask questions properly here. Have a look at How to Ask and Minimal, Complete, and Verifiable example. This site is for questions regarding specific issues with existing code. As it stands, your question is off-topic because you don't explain what behaviour you're getting and what errors you get and on what line they occur. Don't let negative votes or votes to close put you off though. Thanks

    – David Wilson
    Jan 2 at 16:53

















Hi and welcome to Stack Overflow. Its really important to ask questions properly here. Have a look at How to Ask and Minimal, Complete, and Verifiable example. This site is for questions regarding specific issues with existing code. As it stands, your question is off-topic because you don't explain what behaviour you're getting and what errors you get and on what line they occur. Don't let negative votes or votes to close put you off though. Thanks

– David Wilson
Jan 2 at 16:53





Hi and welcome to Stack Overflow. Its really important to ask questions properly here. Have a look at How to Ask and Minimal, Complete, and Verifiable example. This site is for questions regarding specific issues with existing code. As it stands, your question is off-topic because you don't explain what behaviour you're getting and what errors you get and on what line they occur. Don't let negative votes or votes to close put you off though. Thanks

– David Wilson
Jan 2 at 16:53












1 Answer
1






active

oldest

votes


















0














First, I filled the ListBoxes with your numbers using the .AddRange method.



We could have just started with arrays but I am assuming the ListBoxes were filled somewhere else. Converted the ListBox items to an array.



The Intersection is easy with .Intersect method. The second is a little trickier because .Except returns the elements in the first sequence that don't appear in the second. So, we need to use .Except on both arrays and the combine them with .Union.



Private Sub CompareListBoxes()
ListBox1.Items.AddRange(New Object() {1, 3, 5, 11})
ListBox2.Items.AddRange(New Object() {2, 3, 6, 11})
Dim id1() As Integer = (From i In ListBox1.Items Select CInt(i)).ToArray
Dim id2() As Integer = (From i In ListBox2.Items Select CInt(i)).ToArray
Dim Matches As IEnumerable(Of Integer) = id1.Intersect(id2)
'Known as disjunctive union
Dim NotMatches As IEnumerable(Of Integer) = id1.Except(id2).Union(id2.Except(id1))
MessageBox.Show(Matches.Count.ToString)
'TextBox1 and 2 .Multiline = True is set at design time
'Expand the text box size so several lines will be visible
For Each Match As Integer In Matches
TextBox1.Text &= CStr(Match) & Environment.NewLine
Next

For Each NotMatch In NotMatches
TextBox2.Text &= NotMatch.ToString & Environment.NewLine
Next
End Sub


The disjunctive union code was courtesy of @Øyvind Bråthen The opposite of Intersect()



The set theory from Wikipedia https://en.wikipedia.org/wiki/Set_theory



EDIT



Just found out about HashSet(Of T). This collection has a method called .SymetricExceptWith that alters the first HashSet to contain only the elements that are not common to both sets. Called disjunctive union or, as the docs call it, symmetric difference. One caveat, cannot contain duplicate elements.



    Dim hs1 As New HashSet(Of Integer) From {1, 3, 5, 11}
Dim hs2 As New HashSet(Of Integer) From {2, 3, 6, 11}
hs1.SymmetricExceptWith(hs2)
For Each i As Integer In hs1
Debug.Print(i.ToString)
Next
'result 1 6 5 2





share|improve this answer
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    First, I filled the ListBoxes with your numbers using the .AddRange method.



    We could have just started with arrays but I am assuming the ListBoxes were filled somewhere else. Converted the ListBox items to an array.



    The Intersection is easy with .Intersect method. The second is a little trickier because .Except returns the elements in the first sequence that don't appear in the second. So, we need to use .Except on both arrays and the combine them with .Union.



    Private Sub CompareListBoxes()
    ListBox1.Items.AddRange(New Object() {1, 3, 5, 11})
    ListBox2.Items.AddRange(New Object() {2, 3, 6, 11})
    Dim id1() As Integer = (From i In ListBox1.Items Select CInt(i)).ToArray
    Dim id2() As Integer = (From i In ListBox2.Items Select CInt(i)).ToArray
    Dim Matches As IEnumerable(Of Integer) = id1.Intersect(id2)
    'Known as disjunctive union
    Dim NotMatches As IEnumerable(Of Integer) = id1.Except(id2).Union(id2.Except(id1))
    MessageBox.Show(Matches.Count.ToString)
    'TextBox1 and 2 .Multiline = True is set at design time
    'Expand the text box size so several lines will be visible
    For Each Match As Integer In Matches
    TextBox1.Text &= CStr(Match) & Environment.NewLine
    Next

    For Each NotMatch In NotMatches
    TextBox2.Text &= NotMatch.ToString & Environment.NewLine
    Next
    End Sub


    The disjunctive union code was courtesy of @Øyvind Bråthen The opposite of Intersect()



    The set theory from Wikipedia https://en.wikipedia.org/wiki/Set_theory



    EDIT



    Just found out about HashSet(Of T). This collection has a method called .SymetricExceptWith that alters the first HashSet to contain only the elements that are not common to both sets. Called disjunctive union or, as the docs call it, symmetric difference. One caveat, cannot contain duplicate elements.



        Dim hs1 As New HashSet(Of Integer) From {1, 3, 5, 11}
    Dim hs2 As New HashSet(Of Integer) From {2, 3, 6, 11}
    hs1.SymmetricExceptWith(hs2)
    For Each i As Integer In hs1
    Debug.Print(i.ToString)
    Next
    'result 1 6 5 2





    share|improve this answer






























      0














      First, I filled the ListBoxes with your numbers using the .AddRange method.



      We could have just started with arrays but I am assuming the ListBoxes were filled somewhere else. Converted the ListBox items to an array.



      The Intersection is easy with .Intersect method. The second is a little trickier because .Except returns the elements in the first sequence that don't appear in the second. So, we need to use .Except on both arrays and the combine them with .Union.



      Private Sub CompareListBoxes()
      ListBox1.Items.AddRange(New Object() {1, 3, 5, 11})
      ListBox2.Items.AddRange(New Object() {2, 3, 6, 11})
      Dim id1() As Integer = (From i In ListBox1.Items Select CInt(i)).ToArray
      Dim id2() As Integer = (From i In ListBox2.Items Select CInt(i)).ToArray
      Dim Matches As IEnumerable(Of Integer) = id1.Intersect(id2)
      'Known as disjunctive union
      Dim NotMatches As IEnumerable(Of Integer) = id1.Except(id2).Union(id2.Except(id1))
      MessageBox.Show(Matches.Count.ToString)
      'TextBox1 and 2 .Multiline = True is set at design time
      'Expand the text box size so several lines will be visible
      For Each Match As Integer In Matches
      TextBox1.Text &= CStr(Match) & Environment.NewLine
      Next

      For Each NotMatch In NotMatches
      TextBox2.Text &= NotMatch.ToString & Environment.NewLine
      Next
      End Sub


      The disjunctive union code was courtesy of @Øyvind Bråthen The opposite of Intersect()



      The set theory from Wikipedia https://en.wikipedia.org/wiki/Set_theory



      EDIT



      Just found out about HashSet(Of T). This collection has a method called .SymetricExceptWith that alters the first HashSet to contain only the elements that are not common to both sets. Called disjunctive union or, as the docs call it, symmetric difference. One caveat, cannot contain duplicate elements.



          Dim hs1 As New HashSet(Of Integer) From {1, 3, 5, 11}
      Dim hs2 As New HashSet(Of Integer) From {2, 3, 6, 11}
      hs1.SymmetricExceptWith(hs2)
      For Each i As Integer In hs1
      Debug.Print(i.ToString)
      Next
      'result 1 6 5 2





      share|improve this answer




























        0












        0








        0







        First, I filled the ListBoxes with your numbers using the .AddRange method.



        We could have just started with arrays but I am assuming the ListBoxes were filled somewhere else. Converted the ListBox items to an array.



        The Intersection is easy with .Intersect method. The second is a little trickier because .Except returns the elements in the first sequence that don't appear in the second. So, we need to use .Except on both arrays and the combine them with .Union.



        Private Sub CompareListBoxes()
        ListBox1.Items.AddRange(New Object() {1, 3, 5, 11})
        ListBox2.Items.AddRange(New Object() {2, 3, 6, 11})
        Dim id1() As Integer = (From i In ListBox1.Items Select CInt(i)).ToArray
        Dim id2() As Integer = (From i In ListBox2.Items Select CInt(i)).ToArray
        Dim Matches As IEnumerable(Of Integer) = id1.Intersect(id2)
        'Known as disjunctive union
        Dim NotMatches As IEnumerable(Of Integer) = id1.Except(id2).Union(id2.Except(id1))
        MessageBox.Show(Matches.Count.ToString)
        'TextBox1 and 2 .Multiline = True is set at design time
        'Expand the text box size so several lines will be visible
        For Each Match As Integer In Matches
        TextBox1.Text &= CStr(Match) & Environment.NewLine
        Next

        For Each NotMatch In NotMatches
        TextBox2.Text &= NotMatch.ToString & Environment.NewLine
        Next
        End Sub


        The disjunctive union code was courtesy of @Øyvind Bråthen The opposite of Intersect()



        The set theory from Wikipedia https://en.wikipedia.org/wiki/Set_theory



        EDIT



        Just found out about HashSet(Of T). This collection has a method called .SymetricExceptWith that alters the first HashSet to contain only the elements that are not common to both sets. Called disjunctive union or, as the docs call it, symmetric difference. One caveat, cannot contain duplicate elements.



            Dim hs1 As New HashSet(Of Integer) From {1, 3, 5, 11}
        Dim hs2 As New HashSet(Of Integer) From {2, 3, 6, 11}
        hs1.SymmetricExceptWith(hs2)
        For Each i As Integer In hs1
        Debug.Print(i.ToString)
        Next
        'result 1 6 5 2





        share|improve this answer















        First, I filled the ListBoxes with your numbers using the .AddRange method.



        We could have just started with arrays but I am assuming the ListBoxes were filled somewhere else. Converted the ListBox items to an array.



        The Intersection is easy with .Intersect method. The second is a little trickier because .Except returns the elements in the first sequence that don't appear in the second. So, we need to use .Except on both arrays and the combine them with .Union.



        Private Sub CompareListBoxes()
        ListBox1.Items.AddRange(New Object() {1, 3, 5, 11})
        ListBox2.Items.AddRange(New Object() {2, 3, 6, 11})
        Dim id1() As Integer = (From i In ListBox1.Items Select CInt(i)).ToArray
        Dim id2() As Integer = (From i In ListBox2.Items Select CInt(i)).ToArray
        Dim Matches As IEnumerable(Of Integer) = id1.Intersect(id2)
        'Known as disjunctive union
        Dim NotMatches As IEnumerable(Of Integer) = id1.Except(id2).Union(id2.Except(id1))
        MessageBox.Show(Matches.Count.ToString)
        'TextBox1 and 2 .Multiline = True is set at design time
        'Expand the text box size so several lines will be visible
        For Each Match As Integer In Matches
        TextBox1.Text &= CStr(Match) & Environment.NewLine
        Next

        For Each NotMatch In NotMatches
        TextBox2.Text &= NotMatch.ToString & Environment.NewLine
        Next
        End Sub


        The disjunctive union code was courtesy of @Øyvind Bråthen The opposite of Intersect()



        The set theory from Wikipedia https://en.wikipedia.org/wiki/Set_theory



        EDIT



        Just found out about HashSet(Of T). This collection has a method called .SymetricExceptWith that alters the first HashSet to contain only the elements that are not common to both sets. Called disjunctive union or, as the docs call it, symmetric difference. One caveat, cannot contain duplicate elements.



            Dim hs1 As New HashSet(Of Integer) From {1, 3, 5, 11}
        Dim hs2 As New HashSet(Of Integer) From {2, 3, 6, 11}
        hs1.SymmetricExceptWith(hs2)
        For Each i As Integer In hs1
        Debug.Print(i.ToString)
        Next
        'result 1 6 5 2






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 1 at 20:09

























        answered Dec 31 '18 at 22:23









        MaryMary

        3,7992821




        3,7992821

















            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            How to fix TextFormField cause rebuild widget in Flutter