Compare two method count 3 digits

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

mipakteh

Guest
Hi All,

I have two click_button.

Button_2 not count correctly at "017".I suspect because of "string or integer" but I don't how to do.

button_3 show correctly but I need some improve if can.

Thank.

Option Strict On
Option Infer On
Option Explicit On

Imports System.IO
Imports System.Data
Imports System.Text

Imports System.Windows.Forms

Public Class Form1

Private Data As New List(Of String)
Private Data_A As New List(Of String)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TxtFile:
'8257,5321,0181,8279,8661,2120,6641,4000,0752,6975,9849,9106,7661,4522,4287,8613,3279,6296,4498,6003,8273,6642,5201
'6235,5507,0126,9753,0354,0423,0328,6185,8449,3424,1481,1861,3234,5928,3503,1966,0513,2306,2315,3750,0190,1510,0063
'1954,8691,7223,5869,2822,3609,3259,5081,4204,3116,5806,7052,2347,9977,5773,7416,4605,0541,0548,2138,6627,0172,0617

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 sb As New StringBuilder

For I As Integer = 0 To Data.Count - 1

Dim StringToCheck As String = Data(I).ToString
Dim StringsToCheck As String() = StringToCheck.Split(","c)
For Each S As String In StringsToCheck
'0 1 2 3
'012
'013
'123
'023
Dim StringsToFind As String() = {S(0) & S(1) & S(2),
S(0) & S(1) & S(3),
S(1) & S(2) & S(3),
S(0) & S(2) & S(3)}

For J As Integer = 0 To StringsToFind.Count - 1
sb.Append(StringsToFind(J) & vbCrLf)
Data_A.Add(StringsToFind(J))
Next
Next
Next
Me.TextBox2.AppendText(sb.ToString)

End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim sb As New System.Text.StringBuilder
Dim counts As New Dictionary(Of String, Integer)
For Each entry As String In Data_A
counts(entry) = 0
Next
For Each StringToCheck As String In Data
Dim StringsToCheck As String() = StringToCheck.Split(","c)

For Each S As String In StringsToCheck
Dim t As List(Of String) = New List(Of String)
t.Add(S.Substring(0, 3))
t.Add(S.Substring(1, 3))
t.Add(S.Remove(1, 1))
t.Add(S.Remove(2, 1))
For Each ts In t
For Each Find2 As String In Data_A

Dim searchChars As New List(Of Char)(Find2.ToCharArray)
For Each c As Char In ts
If searchChars.Contains(c) Then
searchChars.Remove(c)
If searchChars.Count = 0 Then Exit For
End If
Next
If searchChars.Count = 0 Then counts(Find2) += 1
Next
Next
Next
Next

For Each key As String In (From k In counts.Keys Order By k)
sb.AppendLine("Occurences (" & key & ")= " & counts(key).ToString)
Next
TextBox3.Text = sb.ToString

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim sb_Count_A As New StringBuilder

For Each S As String In Data_A

Dim StringsToFind As String() = {S(0), S(1), S(2)}
For j As Integer = 0 To StringsToFind.Count - 3
Dim Count As Integer = 0
For Each Check As String In Data_A
If StringsToFind(0) <> StringsToFind(1) AndAlso StringsToFind(1) <> StringsToFind(2) AndAlso StringsToFind(0) <> StringsToFind(2) Then
If Check.Contains(StringsToFind(j)) AndAlso Check.Contains(StringsToFind(j + 1)) AndAlso Check.Contains(StringsToFind(j + 2)) Then Count += 1
ElseIf Check = S Then
Count += 1
End If
Next
sb_Count_A.Append("Occurances (" & S & ", " & StringsToFind(j) & StringsToFind(j + 1) & StringsToFind(j + 2) & ")= " & Count.ToString & vbCrLf)
Next
Next
Me.TextBox4.AppendText(sb_Count_A.ToString)
End Sub
End Class

Continue reading...
 
Back
Top