none
Class RRS feed

  • Question

  • Hi All,

    what to do.

    have 5 lines number in text 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

    1.Click Button1 .

    Count 0 to 9 every lines and put the result textbox2

    2.In Listbox1 each lines from  text file.

    0,1,2,3,4

    3,click button 3.

    show the result at lines in listbox1 and counted in textbox2.

     it possible using class info.

    Option Strict On
    Option Infer Off
    Option Explicit On
    
    Imports System.IO
    Imports System.Data
    Imports System.Text
    
    
    Public Class Form1
    
        Dim sData As New List(Of String)
    
        Dim Items As New List(Of Info)
    
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            sData.AddRange(IO.File.ReadAllLines("C:\Users\60129\Documents\5Lines_.txt"))
    
            While (sData(sData.Count - 1) = "")
                sData.RemoveAt(sData.Count - 1)
            End While
    
            For I As Integer = 0 To sData.Count - 1
                TextBox1.AppendText(sData(I) & vbCrLf)
            Next
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim sB As New StringBuilder
    
            For I As Integer = 0 To sData.Count - 1
    
                For J As Integer = 0 To 9
                    Dim sSearch As Integer = J
                    Dim sFind As Integer = sData(I).Count(Function(c As Char) c = sSearch.ToString)
                    sB.Append(sSearch & "  =" & sFind & vbCrLf)
                    Items.Add(New Info With {.A = sSearch, .B = sFind})
                Next
    
            Next
    
            TextBox2.AppendText(sB.ToString)
            TextBox2.AppendText(vbCrLf)
    
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
            For I As Integer = 0 To sData.Count - 1
                ListBox1.Items.Add(I & vbCrLf)
            Next
    
        End Sub
    
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    
            TextBox3.Clear()
    
            Dim SB_A As New StringBuilder
    
            For I As Integer = 0 To ListBox1.Items.Count - 1
                Dim List_1 As String = CStr(ListBox1.Items(I).ToString)
    
                If List_1 = ListBox1.SelectedItem.ToString Then
                    For J As Integer = 0 To Items.Count - 1
                        SB_A.Append(Items(J).ToString & vbCrLf)
                    Next
                End If
            Next
            TextBox3.AppendText(SB_A.ToString)
    
    
        End Sub
    
    End Class
    
    Public Class Info
        Public A As Integer
        Public B As Integer
    
        Public Overrides Function ToString() As String
            Return A.ToString & "  " & B.ToString
        End Function
    End Class
    

    Tuesday, September 17, 2019 2:48 PM

Answers

  • Hi,

    Is that what you want?

    when click item in listbox1 the texbox3 show the result  a counting result from textbox2?

    If so, you just need to determine the exact number of item currently selected.

    You can add ListBox1_SelectedIndexChanged function and try my code as follows.

    Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
            TextBox3.Clear()
            Dim sB As New StringBuilder
            Dim I As Integer = CInt(ListBox1.SelectedItem.ToString)
    
            For J As Integer = 0 To 9
                Dim sSearch As Integer = J
                Dim sFind As Integer = sData(I).Count(Function(c As Char) c = sSearch.ToString)
                sB.Append(sSearch & "  =" & sFind & vbCrLf)
                Items.Add(New Info With {.A = sSearch, .B = sFind})
            Next
    
            TextBox3.AppendText(sB.ToString)
            TextBox3.AppendText(vbCrLf)
        End Sub

    Hope I help you.

    If you have anything else about this issue, please feel free to contact us.

    Best Regards,

    Julie


    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.


    Wednesday, September 18, 2019 2:20 AM
    Moderator

All replies

  • Please explain what exactly the problem is, in as much detail as you can. 

    Also, you will get much better interest if you fix the title to explain the problem in a short sentence please.

     

    Many thanks,
    Pete

     

     


    #PEJL
    Got any nice code? If you invest time in coding an elegant, novel or impressive answer on MSDN forums, why not copy it over to TechNet Wiki, for future generations to benefit from! You'll never get archived again, and you could win weekly awards!

    Have you got what it takes to become this month's TechNet Technical Guru? Join a long list of well known community big hitters, show your knowledge and prowess in your favoured technologies!

    Tuesday, September 17, 2019 2:54 PM
    Moderator
  • Hello,

    Rule of thumb is to write code outside of a form when possible.

    As per Pete's reply, you need to respond to his request as the question as it stands now is vague.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, September 17, 2019 2:59 PM
    Moderator
  • OK,

    Example when we click item in listbox1 the texbox3 show the result  a counting result from textbox2

    Let said we click item no 2 in listbox1 then textbox3 show like bellow;

    0  =7
    1  =12
    2  =7
    3  =7
    4  =10
    5  =15
    6  =7
    7  =7
    8  =10
    9  =10

    thank pete

    Tuesday, September 17, 2019 3:16 PM
  • Hi,

    Is that what you want?

    when click item in listbox1 the texbox3 show the result  a counting result from textbox2?

    If so, you just need to determine the exact number of item currently selected.

    You can add ListBox1_SelectedIndexChanged function and try my code as follows.

    Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
            TextBox3.Clear()
            Dim sB As New StringBuilder
            Dim I As Integer = CInt(ListBox1.SelectedItem.ToString)
    
            For J As Integer = 0 To 9
                Dim sSearch As Integer = J
                Dim sFind As Integer = sData(I).Count(Function(c As Char) c = sSearch.ToString)
                sB.Append(sSearch & "  =" & sFind & vbCrLf)
                Items.Add(New Info With {.A = sSearch, .B = sFind})
            Next
    
            TextBox3.AppendText(sB.ToString)
            TextBox3.AppendText(vbCrLf)
        End Sub

    Hope I help you.

    If you have anything else about this issue, please feel free to contact us.

    Best Regards,

    Julie


    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.


    Wednesday, September 18, 2019 2:20 AM
    Moderator
  • Nicely done!

     

     


    #PEJL
    Got any nice code? If you invest time in coding an elegant, novel or impressive answer on MSDN forums, why not copy it over to TechNet Wiki, for future generations to benefit from! You'll never get archived again, and you could win weekly awards!

    Have you got what it takes to become this month's TechNet Technical Guru? Join a long list of well known community big hitters, show your knowledge and prowess in your favoured technologies!

    Wednesday, September 18, 2019 2:23 AM
    Moderator
  •  Thank juiie...

    I try to do with 'Class Info' if possible.

    you have any Idea?
    • Edited by mipakteh Wednesday, September 18, 2019 2:21 PM add
    Wednesday, September 18, 2019 2:20 PM
  • Mipakteh,

    A Class is meant to be a reusable piece of code. 

    It can be done, but I don't see why you would make such a class if the use of it needs more coding than without the class.  It is like some make their own Add tool, instead of using the + sign. 

    Module Module1
    
        Sub Main()
            Dim fieldToUse = New Info
            Console.WriteLine(fieldToUse.ToString(1, 2))
            Console.ReadLine()
        End Sub
    
    End Module
    Public Class Info
        Public Property First As Integer
        Public Property Second As Integer
    
        Public Function ToString(First As Integer, Second As Integer) As String
            Return First.ToString & "  " & Second.ToString
        End Function
    
    End Class


    Success
    Cor



    • Edited by Cor Ligthert Wednesday, September 18, 2019 3:02 PM
    Wednesday, September 18, 2019 2:37 PM
  • Thank Cor.

    good Explanation

    Thursday, September 19, 2019 1:42 PM