Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class Form1 Public Class Formcnc Dim listitems() As String Dim enditems() As String Dim vectorZn() As Double Dim newlistitems() As String Private Sub readfile() Try listitems = System.IO.File.ReadAllLines(OpenFileDialog1.FileName) Codein.Items.Clear() Codein.Items.AddRange(listitems) proceed.Enabled = True Catch ex As Exception MessageBox.Show("fichier introuvable") End End Try End Sub Private Sub SearchEndCode() Dim array1() As String Dim iter As Integer iter = listitems.Length - 1 Do Until listitems(iter).IndexOf("G0 Z") >= 0 iter -= 1 Loop ReDim array1(iter) ReDim enditems(listitems.Length - 1 - iter) Array.Copy(listitems, iter, enditems, 0, listitems.Length - iter) Array.Copy(listitems, 0, array1, 0, iter - 1) ReDim listitems(iter - (listitems.Length - iter)) Array.Copy(array1, listitems, iter - 2) End Sub Private Sub CreateZvector() 'vectorZn contient tous les cotes des GO Z Dim zn As Double Dim iterzn As Integer Dim iter As Long Dim iternewlist As Long iternewlist = 0 iterzn = 0 ReDim vectorZn(iterzn) For iter = 0 To listitems.Length - 1 If listitems(iter).IndexOf("G0 Z") >= 0 Then 'zn le nombre du Go Z Try zn = Double.Parse(listitems(iter).Substring("G0 Z".Length)) If Not vectorZn.Contains(zn) Then ReDim Preserve vectorZn(iterzn) vectorZn(iterzn) = zn iterzn += 1 End If Catch ex As Exception MessageBox.Show("ERROR CODE G0") End End Try End If Next Array.Sort(vectorZn) End Sub Private Sub GroupGoZ() Dim iterz As Integer Dim iterlist As Integer Dim itergroup As Integer Dim start As Integer Dim flagfirst As Boolean Dim str As String flagfirst = False For iterz = 0 To vectorZn.Length - 1 str = "G0 Z" & vectorZn(iterz) & ".0" start = 0 iterlist = 0 Do Until iterlist > listitems.Length - 1 If listitems(iterlist).IndexOf(str) >= 0 Then If Not flagfirst Then ReDim Preserve newlistitems(iterlist + 1) System.Array.Copy(listitems, newlistitems, iterlist) flagfirst = True newlistitems(iterlist) = "*".PadLeft(60, "*") newlistitems(iterlist + 1) = listitems(iterlist) End If itergroup = iterlist + 1 newlistitems(newlistitems.Length - 1) = str Do While listitems(itergroup).IndexOf("G0 Z") < 0 ReDim Preserve newlistitems(newlistitems.Length) newlistitems(newlistitems.Length - 1) = listitems(itergroup) itergroup += 1 If itergroup = listitems.Length Then Exit Do End If Loop ReDim Preserve newlistitems(newlistitems.Length) newlistitems(newlistitems.Length - 1) = "-".PadLeft(60, "-") iterlist = itergroup ReDim Preserve newlistitems(newlistitems.Length) End If iterlist += 1 Loop Next ReDim Preserve newlistitems(newlistitems.Length - 1 + enditems.Length - 1) Array.Copy(enditems, 0, newlistitems, newlistitems.Length - enditems.Length, enditems.Length) End Sub Private Sub showlist() Dim path As String = "E:\resulttest.txt" ' à modifier selen le fichier System.IO.File.WriteAllLines(path, newlistitems) Try System.IO.File.Exists(path) 'messagebox.show("fichier existe") Catch ex As Exception 'messagebox.show("fichier n'existe pas") End Try End Sub Private Sub GcodeIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileGcodeName.Click OpenFileDialog1.Filter = "Text files (*.txt)|*.txt" If OpenFileDialog1.ShowDialog() = DialogResult.OK Then readfile() End If End Sub Private Sub Formcnc_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load With FileGcodeName .Left = Me.Width / 2 - FileGcodeName.Width / 2 .Top = Me.Top + FileGcodeName.Height End With With proceed .Enabled = False .Left = Me.Width / 2 - proceed.Width / 2 .Top = FileGcodeName.Bottom + 2 End With With Codein .Visible = True .Left = Me.Location.X + 6 .Top = FileGcodeName.Top .Width = Me.Width / 2 - 3 * FileGcodeName.Width / 4 .Height = Me.Height - FileGcodeName.Height * 2 End With With codeout .Left = FileGcodeName.Right + 3 .Top = FileGcodeName.Top .Width = Me.Width / 2 - 3 * FileGcodeName.Width / 4 .Height = Me.Height - FileGcodeName.Height * 2 codeout.Visible = False End With End Sub Private Sub proceed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles proceed.Click SearchEndCode() CreateZvector() GroupGoZ() codeout.Visible = True codeout.Items.Clear() codeout.Items.AddRange(newlistitems) proceed.Enabled = False End Sub End Class End Class
Public Class Form1
end class(le dernier)
Private Sub SearchEndCode() Dim array1() As String Dim iter As Integer iter = listitems.Length - 1 Do Until listitems(iter).IndexOf("G0 Z") >= 0 iter -= 1 Loop ReDim array1(iter) ReDim enditems(listitems.Length - 1 - iter) Array.Copy(listitems, iter, enditems, 0, listitems.Length - iter) Array.Copy(listitems, 0, array1, 0, iter - 1) ReDim listitems(iter - (listitems.Length - iter)) Array.Copy(array1, listitems, iter - 2)'Le tableau de destination n'est pas assez long. Vérifiez destIndex et la longueur, ainsi que les limites inférieures du tableau. End Sub
Private Sub SearchEndCode() Dim array1() As String Dim iter As Integer iter = listitems.Length - 1 Do Until listitems(iter).IndexOf("G0 Z") >= 0 iter -= 1 Loop ReDim enditems(listitems.Length - 1 - iter) Array.Copy(listitems, iter, enditems, 0, listitems.Length - iter) ReDim array1(iter - 1) Array.Copy(listitems, 0, array1, 0, array1.Length) ReDim listitems(array1.Length - 1) Array.Copy(array1, listitems, array1.Length) End Sub
zn = Double.Parse(listitems(iter).Substring("G0 Z".Length))
listitems(iter).Substring("G0 Z".Length)
zn = Double.Parse(listitems(iter).Substring("G0 Z".Length))