I am trying to create an applicaiton that will verify that a large text file used far a CNC machince has all of the operations in order (someone may have edited the file by mistake) I wish to bubble sort the lines of the file while ignroing other lines. I really stuck on how to set up and handle this program. Here is what I have thus far (just started).
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call FilterFile("mydoc.txt", "N")
MessageBox.Show("finished")
Me.Close()
End Sub
Function FilterFile(ByVal sFile As String, ByVal sFilter As String) As Boolean
Dim lines As New List(Of String)
Try
Using sr As New StreamReader(sFile)
While Not sr.EndOfStream
lines.Add(sr.ReadLine)
End While
End Using
For x As Integer = lines.Count - 1 To 0 Step -1
If lines(x).Contains(sFilter) Then
lines.Item(x) = lines.Item(x) & vbLf & " Compare this line"
'''''Bubble Sort Contents here...'''
End If
Next
Using sw As New StreamWriter(sFile)
For Each line As String In lines
sw.WriteLine(line)
Next
End Using
Return True
Catch ex As Exception : Return False : End Try
End Function
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
Here is a sample of the way the text file is formatted:
;
; ====== PROGRAM JUMP IN ======
IF LAST_TOOL==8002
T8002
GOTOF T_8002
ENDIF
; =============================
;
%_N_OP080_01_MPF
;$PATH=/_N_WKS_DIR/_N_OP080_WPD
;###########################################################
;###########################################################
;
N1000 G71
N1010 $AC_TIMER[1]=0 ;TOTAL CYCLE-TIME + LOADING AND UNLOADING
N1020 $AC_TIMER[2]=0 ;SINGLE TIME EACH TOOL
N1030 $AC_TIMER[3]=0 ;TOTAL CYCLE-TIME
;
N1130 $AC_TIMER[2]=-1
N1140 R70=R70+1
N1150 R[R70]=$AC_TIMER[2]
N1160 $AC_TIMER[2]=0
;
; *** insert machine startup code here ***
N100
;
;===================== PROGRAM JUMP IN =====================
N1040 IF (LAST_TOOL <> 0)
N1050 WHEN TRUE DO $R21=1
N1060 T1=LAST_TOOL
N1070 GOTOF (<<"T_"<<LAST_TOOL)
N1080 ENDIF
N1090 WHEN TRUE DO $R21=0
;===========================================================
;
N1100 T_801:
N1110 M21 M11
N1120 G0 G508 X0.0 Y0.0 A=DC(-90.0) B=DC(0.0) M20 M10
;
;###########################################################
The lines N#### need to be re-ordered appropriately (notice that this example is in fact out of order)
Thanks for the help in advance, I am attempting to save some tooling engineers headaches from the CNC equipment crashing.