Class

  • Thread starter Thread starter mipakteh
  • Start date Start date
M

mipakteh

Guest
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

Continue reading...
 
Back
Top