Private Sub CreateZvector()
Catch ex As Exception
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionzn = Double.Parse(listitems(iter).Substring("G0 Z".Length))
ReDim Preserve newlistitems(newlistitems.Length - 1 + enditems.Length - 1)
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 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 Private Sub CreateZvector() 'vectorZn contient tous les cotes des GO Z Dim separator As New System.Globalization.NumberFormatInfo Dim sp As String sp = separator.NumberDecimalSeparator Dim zn As Double Dim iterzn As Integer sp = 1 / 2 sp = sp.Substring(1, 1) 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 If sp <> "." Then listitems(iter) = listitems(iter).Replace(".", sp) End If 'zn le nombre du Go Z Try zn = Double.Parse(listitems(iter).Substring("G0 Z".Length)) listitems(iter) = listitems(iter).Replace(sp, ".") 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).ToString("#0.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 (*.*)|*.* " 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
ReDim Preserve newlistitems(newlistitems.Length - 1 + enditems.Length - 1)
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 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 Private Function GetdecimalSeparator() As Char Dim sp As String sp = 1 / 2 Return (sp.Substring(1, 1)) End Function Private Sub CreateZvector() 'vectorZn contient tous les cotes des GO Z Dim sp As Char Dim zn As Double Dim iterzn As Integer Dim iter As Long Dim iternewlist As Long sp = GetdecimalSeparator() iternewlist = 0 iterzn = 0 ReDim vectorZn(iterzn) For iter = 0 To listitems.Length - 1 If listitems(iter).IndexOf("G0 Z") >= 0 Then If sp <> "." Then listitems(iter) = listitems(iter).Replace(".", sp) End If '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 Dim sp As Char sp = GetdecimalSeparator() flagfirst = False For iterz = 0 To vectorZn.Length - 1 If Math.Truncate(vectorZn(iterz)) - vectorZn(iterz) = 0 Then str = "G0 Z" & vectorZn(iterz).ToString("#0.0") Else str = "G0 Z" & vectorZn(iterz).ToString() End If 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, "*") listitems(iterlist) = listitems(iterlist).Replace(sp, ".") newlistitems(iterlist + 1) = listitems(iterlist) End If itergroup = iterlist + 1 listitems(iterlist) = listitems(iterlist).Replace(sp, ".") newlistitems(newlistitems.Length - 1) = listitems(iterlist) 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 SaveGcode() If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Try System.IO.File.WriteAllLines(SaveFileDialog1.FileName, newlistitems) Catch ex As Exception MessageBox.Show("problème de sauvegarde") End Try End If End Sub Private Sub GcodeIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileGcodeName.Click Save.Enabled = False 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 Save .Enabled = False .Left = Me.Width / 2 - Save.Width / 2 .Top = proceed.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 Save.Enabled = True End Sub Private Sub Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save.Click SaveGcode() End Sub End Class