none
same string in ListBox RRS feed

  • Question

  • Hi All,

    I have few question.It same before this thread ,only a little bit added.

    1.Have count 0 to 9

    2.We get a pair from counted

    3.Put into listBox

    by selected item listBox LineNumber=4 then click button2 the show result in textbox3 like bellow

    0  Is   5   
    1  Is   14   
    2  Is   11   
    3  Is   10   
    4  Is   6   
    5  Is   15   
    6  Is   9   
    7  Is   4   
    8  Is   12   
    9  Is   6   
    LineNumber1


    6280,0689,8129,9546,3877,3065,7630,5954,3681,0133,9917,1656,3476,3534,5891,6136,5329,3062,4304,0359,9408,4010,7549
    0  Is   11   
    1  Is   8   
    2  Is   4   
    3  Is   14   
    4  Is   9   
    5  Is   10   
    6  Is   12   
    7  Is   6   
    8  Is   7   
    9  Is   11   
    LineNumber4

    *item in listbox 1,1,1,1,2,1,1,1,1, and 2,1,1,1,1,1,1,1,1, we assume the same string.

    Option Strict On
    Option Infer Off
    Option Explicit On
    
    Imports System.IO
    Imports System.Data
    Imports System.Text
    
    Public Class Form1
        Private Data As New List(Of String)
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Data.AddRange(IO.File.ReadAllLines("C:\Users\Uset\Documents\3Lines.txt"))
    
            While (Data(Data.Count - 1) = "")
                Data.RemoveAt(Data.Count - 1)
            End While
    
            For i As Integer = 0 To Data.Count - 1
                TextBox1.AppendText(Data(i) & vbCrLf)
            Next
        End Sub
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim Line As Integer = 0
            For J As Integer = 0 To Data.Count - 1
    
                Dim Bucket As New List(Of String)
    
    
                For I As Integer = 0 To 9
                    Dim Number As String = CStr(I)
                    Dim NumberCount As String = Data(J).Count(Function(c As Char) c = Number).ToString
                    TextBox2.AppendText(Number & "  Is   " & NumberCount & "   " & vbCrLf)
                    Bucket.Add(NumberCount)
                Next
                TextBox2.AppendText(vbCrLf)
    
                Line += 1
                TextBox2.AppendText(CStr("LineNumber = " & Line & vbCrLf))
                TextBox2.AppendText(Data(J).ToString & vbCrLf)
    
                Dim Result As New Dictionary(Of String, Integer)
    
                For Each Item As String In Bucket
                    If Result.Keys.Contains(Item) Then
                        Result(Item) += 1
                    Else
                        Result.Add(Item, 1)
                    End If
                Next
    
                Dim List As String = ""
    
                For Each KV As KeyValuePair(Of String, Integer) In Result
                    TextBox2.AppendText(KV.Key & "=" & KV.Value.ToString & " ,")
                    List += KV.Value.ToString
                    List += ", "
                Next
                TextBox2.AppendText(vbCrLf)
    
                ListBox1.Items.Add(List)
    
            Next
    
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            TextBox3.Clear()
            For I As Integer = 0 To ListBox1.Items.Count - 1
                Dim FirstStr1 As String = CStr(ListBox1.Items(I).ToString)
    
                If FirstStr1 = ListBox1.SelectedItem.ToString Then
                    TextBox3.AppendText(Data(I) & vbCrLf)
                End If
            Next
    
            For t As Integer = 0 To 9
                Dim Number As String = CStr(t)
                Dim NumberCount As String = Data(ListBox1.SelectedIndex).Count(Function(c As Char) c = Number).ToString
                TextBox3.AppendText(Number & "  Is   " & NumberCount & "   " & vbCrLf)
            Next
            TextBox3.AppendText("LineNumber" & ListBox1.SelectedIndex + 1)
        End Sub
    
    End Class
    txt file =2311,3461,1965,2553,8363,1540,1969,8385,1281,5885,4951,8862,5830,7845,6239,0927,5144,7703,6525,6011,6153,8522,8221
    3096,9575,5857,7523,2939,8257,1090,7786,3978,2445,5678,6082,5068,3348,3116,0567,5330,3163,8051,1694,6228,0958,0520
    1252,7456,2918,7195,5261,3915,9565,1349,1809,7841,1955,6685,9474,3382,0878,0215,0475,5198,6304,0340,4132,7968,4855
    6280,0689,8129,9546,3877,3065,7630,5954,3681,0133,9917,1656,3476,3534,5891,6136,5329,3062,4304,0359,9408,4010,7549
    5953,7633,5290,3677,9283,0286,4362,5138,3595,1611,5595,2606,0875,6508,4577,1552,9343,5943,0249,0661,7035,7981,3793

    thank


    • Edited by mipakteh Monday, October 29, 2018 3:12 PM add
    Monday, October 29, 2018 3:11 PM

Answers

  • Hi,

    try to modify the code:

     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            TextBox3.Clear()
            For I As Integer = 0 To ListBox1.Items.Count - 1
                Dim FirstStr1 As String = CStr(ListBox1.Items(I).ToString)
    
                If FirstStr1 = ListBox1.SelectedItem.ToString Then
                    TextBox3.AppendText(Data(I \ 2) & vbCrLf)
                End If
    
            Next
            For t As Integer = 0 To 9
                Dim Number As String = CStr(t)
                Dim NumberCount As String = Data(ListBox1.SelectedIndex \ 2).Count(Function(c As Char) c = Number).ToString
                TextBox3.AppendText(Number & "  Is   " & NumberCount & "   " & vbCrLf)
                Items.Add(New myItem With {.A_ = Number, .C_ = NumberCount})
            Next
            TextBox3.AppendText("LineNumber" & (ListBox1.SelectedIndex + 1) \ 2 + 1)
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 30, 2018 2:13 AM