Imports System.IO Imports System.Text 'DUT ANALYSER Public Class Form1 Private path As String, i As Integer ' for this form Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load path = String.Empty End Sub Private Sub odtbut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles odtbut.Click Dim y, z As String ' for this procedure If path = String.Empty Then ' replace Msgbox en DoNet MessageBox.Show("Please, select first a destination file", "No destination file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Else 'select only txt files With OpenFileDialog1 ' With permet de ne pas répéter Openfiledialog1 .Filter = "Text (*.txt)|*.txt" .Multiselect = True If .ShowDialog() = Windows.Forms.DialogResult.OK Then 'open a window to choose the path of the TXT file For Each chemin In .FileNames ' for all the files you have selected 'the file is readed by this application Dim lines() As String = IO.File.ReadAllLines(chemin) Dim nblignes = lines.Length - 1 'lbl1.Text = file(4).ToString 'used to see if the programm worked 'lbl2.Text = file(94).ToString 'comparaison is done with the number of lines : the test stop automatically when it fails, so you always have 'less datas than a passed test : it means less lines ' if the test is failed, this programm will search all lines where test failed 'test y = lines(3).Substring(45, 6) 'we take the serial number (SubString to replace Mid function in DoNet) z = lines(4).Substring(35, 6) lbl1.Text = y lbl2.Text = z 'we write in the TXT document we opened earlier (the final one) With New StreamWriter(path, True, Encoding.Unicode) Dim chaine As String = If(nblignes < 94, "failed", "success") ' If compact in one line .WriteLine(y & ";" & z & ";" & nblignes & chaine) lbl3.Text = nblignes & " " & chaine .Close() End With 'print the number of files tested i += 1 lbl5.Text = i Next Else MessageBox.Show("No file selected, please choose one file", "No file selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) End If End With End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'we pick up the path of the tested folder 'select only txt files With OpenFileDialog2 .Filter = "Text (*.txt)|*.txt" If .ShowDialog() = Windows.Forms.DialogResult.OK Then path = .FileName ' i is the counter of txt documents you analyse i = 0 Button1.Enabled = False 'to avoid missclicks Else MessageBox.Show("No file selected, please choose one file", "No file selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) End If End With End Sub End Class
Dim nblignes = lines.Length - 1
Dim nblignes as Integer = lines.Length - 1
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question