none
To find value KeyValuePair RRS feed

  • Question

  • Hi All,

    I have some data in lines from text file.

    5815,0781,4440,7013,8871,7562,2331,1983,3974,3969,5310,3245,4643,5848,2382,4992,9329,5119,1203,3322,5373,2012,5743
    4300,6339,1944,5551,4302,3461,9228,5252,3968,5935,8290,3288,6698,8167,8376,6989,4666,4000,5999,5486,3316,2978,2429
    7438,0314,2993,1246,4907,6239,9587,1258,9293,6833,5217,8580,9086,2831,7320,6168,0040,1516,7966,3243,9436,6236,6491
    6428,2990,1388,3593,8605,3368,2423,9512,4109,8153,0382,6788,8574,4825,1577,6474,7098,8727,9724,3707,2263,7824,7454
    7955,2565,9386,6289,6579,9336,7286,0137,5029,1394,2067,6202,0390,5472,6166,3606,4049,8110,0735,7450,8423,5930,0278
    5350,7894,1939,8498,2496,8442,5862,5469,3228,1832,9775,5217,7368,5914,7624,3547,6338,1776,5906,1019,6035,2498,0703
    0794,2533,2590,9451,2447,7111,8052,9773,7158,4244,1170,9892,5106,8719,7285,0132,8875,2226,2258,6099,9863,3169,5424
    9857,0905,9343,0371,4828,0659,1482,0296,6339,3233,8955,3759,0848,7657,2093,1292,7786,1930,3379,0061,0127,1024,9115

    every line we search a digits from 0 to 9.

            Dim sr As New System.IO.StreamReader("C:\Users\family\Documents\A.txt")
    
            Do While sr.Peek <> -1
    
                Dim MyItems As New List(Of myItem)
                Dim StringToCheck As String = sr.ReadLine()
    
                For i As Integer = 0 To 9
                    Dim StringToFind As String = CStr(i)
                    Dim Result As Integer = StringToCheck.Count(Function(c As Char) c = StringToFind)
                    MyItems.Add(New myItem With {.Index = i, .Value = Result})
                Next

    After that Value in MyItems we find out the pair ;

    Public Class myItem
        Public Index As Integer
        Public Value As Integer
        Public Overrides Function ToString() As String
            Return Index.ToString & " => " & Value.ToString
        End Function
    End Class
    
    Public Class myData
    
        Private _Items As List(Of myItem)
        Public Property Items As List(Of myItem)
            Get
                Return _Items
            End Get
            Set(ByVal Value As List(Of myItem))
                _Items = Value
    
    
                For Each ITM As myItem In _Items
                    If Result_.Keys.Contains(CStr(ITM.Value)) Then
                        Result_(CStr(ITM.Value)) += 1
                    Else
                        Result_.Add(CStr(ITM.Value), 1)
                    End If
                Next
    
            End Set
        End Property

    Then we show all result using ;

        Public Function DigitsToString() As String
            Dim S As String = ""
            For Each DigitsItem As myItem In Items
                S &= DigitsItem.ToString & vbCrLf
            Next
            For Each KVP As KeyValuePair(Of String, Integer) In Result_
                S &= KVP.Key & "=" & KVP.Value.ToString & ", "
            Next
            Return S
        End Function

    My question is how to find the same value  in KVP.value  for all lines from text file.

    Example;

    bellow have KVP.Value;

    1, 1, 1, 1, 1, 2, 1, 1, 1 

    if there have 1, 1, 2, 1, 1, 1, 1, 1, 1 or .... it same

    Don't care where is position value.

    The Textbox1 show All ;

    6=1, 11=1, 12=1, 17=1, 10=1, 9=2, 3=1, 7=1, 8=1, 

    ..........

    ..........

    Thank.

    the whole code is;

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Imports System.IO
    Imports System.Data
    
    
    Public Class Form1
    
        Dim DataLines As New List(Of myData)
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            TextBox1.Clear()
    
            Dim sr As New System.IO.StreamReader("C:\Users\family\Documents\B.txt")
    
            Do While sr.Peek <> -1
    
                Dim MyItems As New List(Of myItem)
                Dim StringToCheck As String = sr.ReadLine()
    
                For i As Integer = 0 To 9
                    Dim StringToFind As String = CStr(i)
                    Dim Result As Integer = StringToCheck.Count(Function(c As Char) c = StringToFind)
                    MyItems.Add(New myItem With {.Index = i, .Value = Result})
                Next
                'If sr.Peek = -1 Then Exit Sub
    
    
                Dim thisData As New myData With {.Items = MyItems}
                DataLines.Add(thisData)
    
    
            Loop
    
            For I As Integer = 0 To DataLines.Count - 1
                TextBox1.AppendText(DataLines(I).DigitsToString)
                TextBox1.AppendText(vbCrLf)
            Next
    
        End Sub
    End Class
    Public Class myItem
        Public Index As Integer
        Public Value As Integer
        Public Overrides Function ToString() As String
            Return Index.ToString & " => " & Value.ToString
        End Function
    End Class
    
    Public Class myData
    
        Private _Items As List(Of myItem)
        Public Property Items As List(Of myItem)
            Get
                Return _Items
            End Get
            Set(ByVal Value As List(Of myItem))
                _Items = Value
    
    
                For Each ITM As myItem In _Items
                    If Result_.Keys.Contains(CStr(ITM.Value)) Then
                        Result_(CStr(ITM.Value)) += 1
                    Else
                        Result_.Add(CStr(ITM.Value), 1)
                    End If
                Next
    
            End Set
        End Property
    
        Dim Result_ As New Dictionary(Of String, Integer)
    
        Public Function DigitsToString() As String
            Dim S As String = ""
            For Each DigitsItem As myItem In Items
                S &= DigitsItem.ToString & vbCrLf
            Next
            For Each KVP As KeyValuePair(Of String, Integer) In Result_
                S &= KVP.Key & "=" & KVP.Value.ToString & ", "
            Next
            Return S
        End Function
    
    
    
    End Class
    

    • Edited by mipakteh Monday, September 4, 2017 5:26 AM add
    Monday, September 4, 2017 2:47 AM

Answers

  • I try to do by code bellow.It succesed but I don't know to put this code in Class as public function.

    I do not understand why you are making random changes to your class.  The class code you have works - you only need to add one new property to support the new task.  Add the new property as described above.  Then you can use code like:

    Dim thisData As New myData With _ {.Line = StringToCheck, _ .Pairs = Result_, _ .Items = myItems} DataLines.Add(thisData) Loop For I As Integer = 0 To DataLines.Count - 2 TextBox1.AppendText("Comparing Line " & I.ToString & " : " & DataLines(I).ValuesToString & vbCrLf) For J As Integer = I + 1 To DataLines.Count - 1 TextBox1.AppendText("To " & J.ToString & " : " & DataLines(J).ValuesToString & vbCrLf)
    ' If DataLines(I).Values is equal to DataLines(J).Values then
    ' show the 'line'

    Next Next End Sub

    so that the only thing you need is a temporary ToString method to show that array in the format you want, and some code to do the actual comparison of the two arrays.  Then you can add code to format the answer (which is still not clear whether it's the line index or the line data, and which line) based on the comparison.
    • Marked as answer by mipakteh Thursday, September 14, 2017 7:29 AM
    Saturday, September 9, 2017 5:24 AM

All replies

  • My question is how to find the same value  in KVP.value  for all lines from text file.

    Use the list of pairs to get the values into an array of integer.
    Sort the array.
    Expose the sorted array of values as a property of the MyData object.
    Iterate through the DataLines collection comparing the sorted value array property of instance.

    You have deleted a lot of code from the class - it needs to be added back.

    Monday, September 4, 2017 5:49 AM
  • I can't do it.Need you help
    Monday, September 4, 2017 7:25 AM
  • I can't do it.Need you help

    This is the first two tasks.  You can do the third by comparing the Values properties for each pair of objects in the Datalines collection.  You will need to decide how you will accumulate the matching objects - a list of lists would work.

    Note that now you have done all the work in establishing the class with its properties and methods, the calculation of the values array simply required a new property with three lines of code.  That simplification is the reason that you built the class.

        ''' <summary>
        ''' Values from the list of pairs, sorted ascending.
        ''' </summary>
        ''' <value></value>
        ''' <returns>Array of Integer</returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Values As Integer()
            Get
                Dim V() As Integer = Pairs.Values.ToArray
                Array.Sort(V)
                Return (V)
            End Get
        End Property
    Monday, September 4, 2017 10:03 AM
  • Acamar, I can't do....

    I need your  code.

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Imports System.IO
    Imports System.Data
    
    Public Class Form1
    
        Dim DataLines As New List(Of myData)
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            TextBox1.Clear()
    
            Dim sr As New System.IO.StreamReader("C:\Users\User\Documents\B.txt")
    
            Do While sr.Peek <> -1
    
                Dim MyItems As New List(Of myItem)
                Dim StringToCheck As String = sr.ReadLine()
    
                For i As Integer = 0 To 9
                    Dim StringToFind As String = CStr(i)
                    Dim Result As Integer = StringToCheck.Count(Function(c As Char) c = StringToFind)
                    MyItems.Add(New myItem With {.Index = i, .Value = Result})
                Next
                'If sr.Peek = -1 Then Exit Sub
    
                Dim Digits As New myData With {.Items = MyItems}
                DataLines.Add(Digits)
    
            Loop
    
            For I As Integer = 0 To DataLines.Count - 1
                TextBox1.AppendText(DataLines(I).DigitsToString & vbCrLf)
            Next
    
    
    
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    
            For I As Integer = 0 To DataLines.Count - 1
                TextBox2.AppendText(DataLines(I).DigitsToString & vbCrLf)
            Next
    
    
        End Sub
    
    End Class
    
    
    
    Public Class myItem
        Public Index As Integer
        Public Value As Integer
        Public Overrides Function ToString() As String
            Return Index.ToString & " => " & Value.ToString
        End Function
    End Class
    
    
    
    Public Class myData
        Private _Items As List(Of myItem)
        Public Result_ As New Dictionary(Of Integer, Integer)
        Public Count As Integer
        Public Total As Integer
        Public Overrides Function ToString() As String
            Return Count.ToString & " => " & Total.ToString
        End Function
    
    
        Public Property Items As List(Of myItem)
            Get
                Return _Items
            End Get
            Set(ByVal Value As List(Of myItem))
                _Items = Value
    
                For Each ITM As myItem In _Items
                    If Result_.Keys.Contains(ITM.Value) Then
                        Result_(ITM.Value) += 1
                    Else
                        Result_.Add((ITM.Value), 1)
                    End If
                Next
    
    
            End Set
        End Property
    
    
        Public Function DigitsToString() As String
            Dim myPairs As New List(Of myData)
    
            Dim S As String = " KeyPairs :"
            For Each KVP As KeyValuePair(Of Integer, Integer) In Result_
                S &= KVP.Key & "=" & KVP.Value & ", "
                myPairs.Add(New myData With {.Count = KVP.Key, .Total = KVP.Value})
            Next
    
    
            'Dim P As String = " Pairs :"
    
            For Each ITP As myData In myPairs
                If ITP.Total = 3 Then
                    S &= "     Pair  = " & ITP.ToString
                End If
            Next
    
            Return S
    
        End Function
        Public ReadOnly Property Values_ As Integer()
            Get
                Dim V() As Integer = Result_.Values.ToArray
                Array.Sort(V)
                Return (V)
            End Get
        End Property
    
    
    End Class
    

    Tuesday, September 5, 2017 2:44 PM
  • Acamar, I can't do....

    Why have you re-written the class?  That class code was working and did not need to be changed, other than for the addition of the new property to assist in the new calculation.

    You can test the routine to compare two arrays without using that data - just create some dummy arrays, some that match and some that don't.

    Then describe what you are trying to do as the current description is not sufficient. You have indicated that the result of the test will be one pair/value list, but you haven't indicated how that one list got selected.   If there was a match of the value arrays then there must have been at least two lines that matched.  The pair/value lists will be different, so how do you select the one to display?

    Tuesday, September 5, 2017 10:24 PM
  • you dont need to do all that just get the data from the file to a list create a linq query to search the desired key

     Private infile As StreamReader
     Private wordlist As New list(Of String)
    If Not OpenInputFile() Then Return
    
            ' Read each line and insert each new word into the
            ' dictionary. For each existing word, add its line
            ' number to the list for that word entry.
            Dim linenum As Integer = 0
            Dim filterOut As Char() = ("?':;.,!""").ToCharArray()
    
            Do While Not infile.EndOfStream()
                Dim temp As String = infile.ReadLine()
                If temp.Trim().Length = 0 Then Continue Do
                Dim words() As String = temp.Split(" "c)
    wordlist.add(words)
    loop
    End if 
    End sub
    
    Private Sub txtbxsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtbxsearch.TextChanged
    dim find = from word in wordlist
    select txtbxsearch.Text
    listbox1.items=find
    End sub

    Wednesday, September 6, 2017 7:30 PM
  • Please try this as a console app and let me know if it is what you are seeking.
    I need to make sure you're looking for the contents of a string IN ANY ORDER
    inside the strings found in the file.

    Imports System.IO Module Module1 ''' <summary> ''' Parses file containing comma separated text and carriage return/linefeed ''' </summary> ''' <param name="strFileName">Full patth of file to parse</param> ''' <returns>List of Strings</returns> Function LoadData(ByVal strFileName As String) As List(Of String) Dim arr_strSplits As Char() = {",", Chr(10), Chr(13)} ' will be used to split comma and new line ' split and don't keep blanks Return File.ReadAllLines(strFileName) _ .SelectMany(Function(s) s.Split(arr_strSplits, StringSplitOptions.RemoveEmptyEntries)) _ .ToList() End Function ''' <summary> ''' Searches for a string where all characters match all characters of strings in a list ''' regardless of order of the characters ''' </summary> ''' <param name="lst_strSource">Source list of strings to search</param> ''' <param name="strCriteria">String sought in list</param> ''' <returns>List of KVP i-to-s where found</returns> Function DoFind(ByRef lst_strSource As List(Of String), ByVal strCriteria As String) As List(Of KeyValuePair(Of Integer, String)) Return lst_strSource _ .Select(Function(s, i) New KeyValuePair(Of Integer, String)(i, s)) _ .Where(Function(KVP) New String(KVP.Value.OrderBy(Function(c) c).ToArray()) _ .Equals(New String(strCriteria.OrderBy(Function(c) c).ToArray()))).ToList End Function ''' <summary> ''' Generates a string to be used as a report of what was found ''' </summary> ''' <param name="lst_kvp_i2sResult">Resulting list from the search</param> ''' <returns>String containing formatted report</returns> Function GenReport(ByRef lst_kvp_i2sResult As List(Of KeyValuePair(Of Integer, String))) As String Dim strNewLine As String = Environment.NewLine Return String.Format(("Found {0} match{1}:" + strNewLine + "{2}"), lst_kvp_i2sResult.Count, If(lst_kvp_i2sResult.Count.Equals(1), "", "es"), String.Join(strNewLine, lst_kvp_i2sResult.Select(Function(kvp) String.Format("{0} -- {1}", kvp.Key, kvp.Value)))) End Function Sub Main() Dim lst_strData As List(Of String) = LoadData("c:/science/data/a.txt") Dim strPatternToSearch As String = "1558" Dim lst_kvp_i2sResult As List(Of KeyValuePair(Of Integer, String)) = DoFind(lst_strData, strPatternToSearch) Console.WriteLine(GenReport(lst_kvp_i2sResult)) End Sub End Module



    TEHIII

    Thursday, September 7, 2017 3:42 AM
  • Good..

    Thank THines

    May be for next project.You find 4 digits the whole line in Text File.

    If you see,we have keyValuePair (.Count=KVP.key,.Total=KVP.Value) for every lines.

    I just to find out which line having the same of ".Count=KVP.key".

    Saturday, September 9, 2017 3:50 AM
  • thank TATARPPRO.

      ' Read each line and insert each new word into the
            ' dictionary. For each existing word, add its line
            ' number to the list for that word entry.

    It possible give me the full code.

    Saturday, September 9, 2017 3:53 AM
  • Acamar sorry, I don't know how to use;

     Public ReadOnly Property Values_ As Integer()
            Get
                Dim V() As Integer = Result_.Values.ToArray
                Array.Sort(V)
                Return (V)
            End Get
        End Property

    I try to do by code bellow.It succesed but I don't know to put this code in Class as public function.

                Dim S As String = ""
    
                For Each KVP As KeyValuePair(Of Integer, Integer) In Result_
                    S &= KVP.Key & "=" & KVP.Value.ToString & ", "
                    MyItems_.Add(New myData With {.Digit = KVP.Key, .Find = KVP.Value})
                    Dim thisData As New myData With {.Items = MyItems, .Line = StringToCheck, .Digit = KVP.Key, .Find = KVP.Value}
                    DataLines.Add(thisData)
    
                Next

    then Display the result by Click Button,

              For Each ITP As myData In MyItems_
                    TextBox2.AppendText(ITP.Find & " ,")
                    If ITP.Find = 3 Then
                        TextBox3.AppendText(ITP.ToString & "      { " & S & vbCrLf)
    
                    End If
                Next
                TextBox3.AppendText(vbCrLf)

    The Full code like this;

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Imports System.IO
    Imports System.Data
    
    Public Class Form1
    
        Dim DataLines As New List(Of myData)
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            TextBox1.Clear()
    
            Dim sr As New System.IO.StreamReader("C:\Users\family\Documents\B.txt")
    
            Do While sr.Peek <> -1
    
                Dim MyItems As New List(Of myItem)
                Dim StringToCheck As String = sr.ReadLine()
    
                For i As Integer = 0 To 9
                    Dim StringToFind As String = CStr(i)
                    Dim Result As Integer = StringToCheck.Count(Function(c As Char) c = StringToFind)
                    MyItems.Add(New myItem With {.Index = i, .Value = Result})
                Next
                'If sr.Peek = -1 Then Exit Sub
    
                Dim MyItems_ As New List(Of myData)
                Dim Result_ As New Dictionary(Of Integer, Integer)
                Dim Pair As New Dictionary(Of Integer, Integer)
    
                For Each ITM As myItem In MyItems
                    If Result_.Keys.Contains(ITM.Value) Then
                        Result_(ITM.Value) += 1
                    Else
                        Result_.Add((ITM.Value), 1)
                    End If
                Next
    
                Dim S As String = ""
    
                For Each KVP As KeyValuePair(Of Integer, Integer) In Result_
                    S &= KVP.Key & "=" & KVP.Value.ToString & ", "
                    MyItems_.Add(New myData With {.Digit = KVP.Key, .Find = KVP.Value})
                    Dim thisData As New myData With {.Items = MyItems, .Line = StringToCheck, .Digit = KVP.Key, .Find = KVP.Value}
                    DataLines.Add(thisData)
    
                Next
    
                TextBox1.AppendText(S)
                TextBox1.AppendText(vbCrLf)
                TextBox2.AppendText(vbCrLf)
    
                For Each ITP As myData In MyItems_
                    TextBox2.AppendText(ITP.Find & " ,")
                    If ITP.Find = 3 Then
                        TextBox3.AppendText(ITP.ToString & "      { " & S & vbCrLf)
    
                    End If
                Next
                TextBox3.AppendText(vbCrLf)
    
            Loop
    
        End Sub
    End Class
    Public Class myItem
        Public Index As Integer
        Public Value As Integer
        Public Overrides Function ToString() As String
            Return Index.ToString & " => " & Value.ToString
        End Function
    End Class
    
    Public Class myData
    
        Private _Items As List(Of myItem)
        Public Line As String
    
        Public Digit As Integer
        Public Find As Integer
    
        Public Overrides Function ToString() As String
            Return Digit.ToString & " => " & Find.ToString
        End Function
    
        Public Property Items As List(Of myItem)
            Get
                Return _Items
            End Get
            Set(ByVal Value As List(Of myItem))
                _Items = Value
    
            End Set
        End Property
    
        Public ReadOnly Property _Digit As Integer
            Get
                Return Digit
            End Get
        End Property
        Public ReadOnly Property _Find As Integer
            Get
                Return Find
            End Get
        End Property
    
    End Class
    

    Saturday, September 9, 2017 3:58 AM
  • I try to do by code bellow.It succesed but I don't know to put this code in Class as public function.

    I do not understand why you are making random changes to your class.  The class code you have works - you only need to add one new property to support the new task.  Add the new property as described above.  Then you can use code like:

    Dim thisData As New myData With _ {.Line = StringToCheck, _ .Pairs = Result_, _ .Items = myItems} DataLines.Add(thisData) Loop For I As Integer = 0 To DataLines.Count - 2 TextBox1.AppendText("Comparing Line " & I.ToString & " : " & DataLines(I).ValuesToString & vbCrLf) For J As Integer = I + 1 To DataLines.Count - 1 TextBox1.AppendText("To " & J.ToString & " : " & DataLines(J).ValuesToString & vbCrLf)
    ' If DataLines(I).Values is equal to DataLines(J).Values then
    ' show the 'line'

    Next Next End Sub

    so that the only thing you need is a temporary ToString method to show that array in the format you want, and some code to do the actual comparison of the two arrays.  Then you can add code to format the answer (which is still not clear whether it's the line index or the line data, and which line) based on the comparison.
    • Marked as answer by mipakteh Thursday, September 14, 2017 7:29 AM
    Saturday, September 9, 2017 5:24 AM
  • Thank Acamar.

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Imports System.IO
    Imports System.Data
    
    
    Public Class Form1
        Dim DataLines As New List(Of myData)
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            TextBox1.Clear()
    
            Dim sr As New System.IO.StreamReader("C:\Users\ERAS\Documents\A.txt")
    
            Do While sr.Peek <> -1
                Dim myItems As New List(Of myItem)
    
                Dim StringToCheck As String = sr.ReadLine()
    
                For i As Integer = 0 To 9
                    Dim StringToFind As String = CStr(i)
                    Dim Result As Integer = StringToCheck.Count(Function(c As Char) c = StringToFind)
                    myItems.Add(New myItem With {.Index = i, .Value = Result})
                Next
    
                Dim Digits As New myData With {.Items = myItems, .Line = StringToCheck}
                DataLines.Add(Digits)
    
            Loop
    
            For I As Integer = 0 To DataLines.Count - 1
                TextBox1.AppendText(DataLines(I).Values_ToString & vbCrLf)
            Next
    
            For I As Integer = 0 To DataLines.Count - 2
                TextBox2.AppendText("Comparing Line " & I.ToString & " : " & DataLines(I).Values_ToString & vbCrLf)
                For J As Integer = I + 1 To DataLines.Count - 1
                    TextBox2.AppendText("To           " & J.ToString & " : " & DataLines(J).Values_ToString & vbCrLf)
                    If DataLines(I).Values_ToString = DataLines(J).Values_ToString Then
                        TextBox3.AppendText(DataLines(I).Compare_ToString & vbCrLf)
                    End If
                Next
            Next
    
        End Sub
    End Class
    
    Public Class myItem
    
        Public Index As Integer
        Public Value As Integer
        Public Overrides Function ToString() As String
            Return Index.ToString & " => " & Value.ToString
        End Function
    
    End Class
    
    
    Public Class myData
    
        Public Result_ As New Dictionary(Of Integer, Integer)
        Public myPairs As New List(Of myData)
    
        Public KKey As Integer
        Public KValue As Integer
        Public Line As String
        Public Overrides Function ToString() As String
            Return KKey.ToString & " => " & KValue.ToString
        End Function
    
        Private _Items As List(Of myItem)
    
        Public Property Items As List(Of myItem)
            Get
                Return _Items
            End Get
            Set(ByVal Value As List(Of myItem))
                _Items = Value
    
    
                For Each ITM As myItem In _Items
                    If Result_.Keys.Contains(ITM.Value) Then
                        Result_(ITM.Value) += 1
                    Else
                        Result_.Add((ITM.Value), 1)
                    End If
                Next
                Dim S As String = " KeyPairs :"
                For Each KVP As KeyValuePair(Of Integer, Integer) In Result_
                    S &= KVP.Key & "=" & KVP.Value & ", "
                    myPairs.Add(New myData With {.KKey = KVP.Key, .KValue = KVP.Value})
    
                Next
    
            End Set
        End Property
    
        Public ReadOnly Property Values_ As Integer()
            Get
                Dim V() As Integer = Result_.Values.ToArray
                Array.Sort(V)
                Return (V)
            End Get
        End Property
    
        Public Function Values_ToString() As String
    
            Dim S As String = ""
            For Each KVPValue As Integer In Values_
                S &= KVPValue.ToString & " ,"
            Next
            Return S
        End Function
    
        Public Function Compare_ToString() As String
    
            Dim S As String = ""
            For Each KPair As myData In myPairs
                S &= KPair.ToString & " ,"
            Next
            Return S
        End Function
    End Class

    One more question about;

    If DataLines(I).Values_ToString = DataLines(J).Values_ToString Then
                        TextBox3.AppendText(DataLines(I).Compare_ToString & vbCrLf)
    End If

    How to write code in Compare_ToString, Do not repeat comparing if that line it finish compare.

    Thank

    Thursday, September 14, 2017 7:29 AM
  • How to write code in Compare_ToString, Do not repeat comparing if that line it finish compare.

    Do you mean this line:
      'If DataLines(I).Values is equal to DataLines(J).Values then' ?

    You need to consider how you would compare two arrays if you were doing it by hand, using pencil and paper.  You would start by first checking that the arrays are the same size, because if they are not the same size then they cannot be equal.  Then you would assume that they are equal.  To prove that you would compare each corresponding pair of items from the two arrays. As soon as two corresponding items are not the same you know that the arrays are not the same.  If you get to the end of the arrays and none of the corresponding pairs has been different, then the whole array must be the same.

     

    Thursday, September 14, 2017 10:56 AM