I have a text file with a four field array like this:
DET-01-002737,DET-01-002737,YES,6423 9764b32fefc915a 593f41bdb5730.
My program sorts them in the order where the 3rd field says "Yes" or "NO". "YES" means it isa parent, "NO" means it is the child of that parent as long as field 2 of the parent is equal to field 2 of the child. Forn some reason my code is printing some of the children multiple times.
example of some of the output:
DET-01-002737,DET-01-002737,YES,6423 9764b32fefc915a 593f41bdb5730
DET-01-002738,DET-01-002737,NO,64239 764b32fefc915a5 93f41bdb5730
DET-01-002739,DET-01-002737,NO,64239 764b32fefc915a5 93f41bdb5730
DET-01-002740,DET-01-002737,NO,64239 764b32fefc915a5 93f41bdb5730
DET-01-002741,DET-01-002737,NO,64239 764b32fefc915a5 93f41bdb5730
DET-01-002742,DET-01-002737,NO,64239 764b32fefc915a5 93f41bdb5730
DET-01-002743,DET-01-002737,NO,64239 764b32fefc915a5 93f41bdb5730
DET-01-002744,DET-01-002737,NO,64239 764b32fefc915a5 93f41bdb5730
DET-01-002745,DET-01-002737,NO,64239 764b32fefc915a5 93f41bdb5730
DET-01-002746,DET-01-002737,NO,64239 764b32fefc915a5 93f41bdb5730
DET-01-002747,DET-01-002737,NO,64239 764b32fefc915a5 93f41bdb5730
DET-01-002739,DET-01-002737,NO,BE29D 4AC2C809C4C3703 E7B57272AA4B
DET-01-002740,DET-01-002737,NO,BE29D 4AC2C809C4C3703 E7B57272AA4B
DET-01-002741,DET-01-002737,NO,BE29D 4AC2C809C4C3703 E7B57272AA4B
DET-01-002742,DET-01-002737,NO,BE29D 4AC2C809C4C3703 E7B57272AA4B
if the field(2) is "NO" it gets appended under "YES" if field(1) is = field(2)
Here is the code:
Dim EID, EID_2 As String
Dim GID, GID_2 As String
Dim IsParent, IsParent_2 As String
Dim MD5, MD5_2 As String
Dim lineString As String = ""
Dim lineString2 As String = ""
Dim dlmtr As String = ","
Dim fields() As String
Dim fields_2() As String
Dim sr As StreamReader
Dim rdr As StreamReader
Dim MD5_Log As StreamWriter
Dim error_log As StreamWriter
Dim error_log_2 As StreamWriter
Dim loadFile As String = Me.txtLoadFile. Text
Dim folder As String = Me.txtOutputFld r.Text
If Me.txtLoadFile. Text <> "" And Me.txtOutputFld r.Text <> "" Then
Try
DeleteBlankLine s()
sr = New StreamReader(fo lder & "\" & "MD5_clean.txt" )
MD5_Log = New StreamWriter(fo lder & "\" & "MD5_log.tx t", False)
error_log = New StreamWriter(fo lder & "\" & "error_log.txt" , False)
error_log_2 = New StreamWriter(fo lder & "\" & "Child_error_lo g.txt", False)
error_log_2.Aut oFlush = True
MD5_Log.AutoFlu sh = True
error_log.AutoF lush = True
Me.StatusBar1.T ext = "Processing File........... ........."
While sr.Peek() <> -1
lineString = sr.ReadLine()
If Not lineString = "" Then
fields = lineString.Spli t(dlmtr)
If fields.Length <> 4 Then
error_log.Write Line(lineString & "|" & "Error:Fiel d Length <> 4")
'GoTo errorskip
End If
Else
error_log.Write Line(sr.Peek & "Test")
End If
EID = fields(0)
GID = fields(1)
IsParent = fields(2)
MD5 = fields(3)
If IsParent <> "YES" And IsParent <> "NO" Then
error_log.Write Line("No IsParent Identified")
ElseIf IsParent = "YES" Then
'write the parent and its children
MD5_Log.WriteLi ne(EID & "," & GID & "," & IsParent & "," & MD5)
End If
rdr = New StreamReader(fo lder & "\MD5_clean.txt ")
While rdr.Peek() <> -1
lineString2 = rdr.ReadLine()
fields_2 = lineString2.Spl it(dlmtr)
If fields_2.Length <> 4 Then
error_log_2.Wri teLine(lineStri ng2 & "|" & "Error:Fiel d length <> 4")
'GoTo errorskip
Else
EID_2 = fields_2(0)
GID_2 = fields_2(1)
IsParent_2 = fields_2(2)
MD5_2 = fields_2(3)
If IsParent_2 <> "YES" And IsParent_2 <> "NO" Then
error_log.Write Line(lineString & "|" & "IsParent Field not Yes or No")
Else
If EID_2 = "" Or GID_2 = "" Or IsParent <> "YES" Or MD5_2 = "" Then
error_log.Write Line(lineString & "|" & "Error:Valu e missing")
End If
If (IsParent_2 <> "YES") And (GID_2 = GID) And (MD5_2 <> MD5) Then
MD5_Log.WriteLi ne(EID_2 & "," & GID_2 & "," & IsParent_2 & "," & MD5)
End If
End If
End If
End While
End While
Catch ex As Exception
'System.Diagnos tics.Debug.Writ eLine(ex.Messag e)
MessageBox.Show (ex.Message)
Finally
rdr.Close()
rdr = Nothing
Me.StatusBar1.T ext = "Ready"
MessageBox.Show ("Complete")
End Try
Else
If Me.txtLoadFile. Text = "" Then
MessageBox.Show ("Please enter the load file")
Me.btnLoadFile. Focus()
ElseIf Me.txtOutputFld r.Text = "" Then
MessageBox.Show ("Please select an output directory")
Me.btnOutputFld r.Focus()
End If
End If
Cant for the life of me figure out what is wrong with my looping. Is my errorskip in the wrong place?