I have a text file with a four field array like this:
DET-01-002737,DET-01-002737,YES,64239764b32fefc915a593f41bdb5730.
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,64239764b32fefc915a593f41bdb5730
DET-01-002738,DET-01-002737,NO,64239764b32fefc915a593f41bdb5730
DET-01-002739,DET-01-002737,NO,64239764b32fefc915a593f41bdb5730
DET-01-002740,DET-01-002737,NO,64239764b32fefc915a593f41bdb5730
DET-01-002741,DET-01-002737,NO,64239764b32fefc915a593f41bdb5730
DET-01-002742,DET-01-002737,NO,64239764b32fefc915a593f41bdb5730
DET-01-002743,DET-01-002737,NO,64239764b32fefc915a593f41bdb5730
DET-01-002744,DET-01-002737,NO,64239764b32fefc915a593f41bdb5730
DET-01-002745,DET-01-002737,NO,64239764b32fefc915a593f41bdb5730
DET-01-002746,DET-01-002737,NO,64239764b32fefc915a593f41bdb5730
DET-01-002747,DET-01-002737,NO,64239764b32fefc915a593f41bdb5730
DET-01-002739,DET-01-002737,NO,BE29D4AC2C809C4C3703E7B57272AA4B
DET-01-002740,DET-01-002737,NO,BE29D4AC2C809C4C3703E7B57272AA4B
DET-01-002741,DET-01-002737,NO,BE29D4AC2C809C4C3703E7B57272AA4B
DET-01-002742,DET-01-002737,NO,BE29D4AC2C809C4C3703E7B57272AA4B
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.txtOutputFldr.Text
If Me.txtLoadFile.Text <> "" And Me.txtOutputFldr.Text <> "" Then
Try
DeleteBlankLines()
sr = New StreamReader(folder & "\" & "MD5_clean.txt")
MD5_Log = New StreamWriter(folder & "\" & "MD5_log.txt", False)
error_log = New StreamWriter(folder & "\" & "error_log.txt", False)
error_log_2 = New StreamWriter(folder & "\" & "Child_error_log.txt", False)
error_log_2.AutoFlush = True
MD5_Log.AutoFlush = True
error_log.AutoFlush = True
Me.StatusBar1.Text = "Processing File...................."
While sr.Peek() <> -1
lineString = sr.ReadLine()
If Not lineString = "" Then
fields = lineString.Split(dlmtr)
If fields.Length <> 4 Then
error_log.WriteLine(lineString & "|" & "Error:Field Length <> 4")
'GoTo errorskip
End If
Else
error_log.WriteLine(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.WriteLine("No IsParent Identified")
ElseIf IsParent = "YES" Then
'write the parent and its children
MD5_Log.WriteLine(EID & "," & GID & "," & IsParent & "," & MD5)
End If
rdr = New StreamReader(folder & "\MD5_clean.txt")
While rdr.Peek() <> -1
lineString2 = rdr.ReadLine()
fields_2 = lineString2.Split(dlmtr)
If fields_2.Length <> 4 Then
error_log_2.WriteLine(lineString2 & "|" & "Error:Field 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.WriteLine(lineString & "|" & "IsParent Field not Yes or No")
Else
If EID_2 = "" Or GID_2 = "" Or IsParent <> "YES" Or MD5_2 = "" Then
error_log.WriteLine(lineString & "|" & "Error:Value missing")
End If
If (IsParent_2 <> "YES") And (GID_2 = GID) And (MD5_2 <> MD5) Then
MD5_Log.WriteLine(EID_2 & "," & GID_2 & "," & IsParent_2 & "," & MD5)
End If
End If
End If
End While
End While
Catch ex As Exception
'System.Diagnostics.Debug.WriteLine(ex.Message)
MessageBox.Show(ex.Message)
Finally
rdr.Close()
rdr = Nothing
Me.StatusBar1.Text = "Ready"
MessageBox.Show("Complete")
End Try
Else
If Me.txtLoadFile.Text = "" Then
MessageBox.Show("Please enter the load file")
Me.btnLoadFile.Focus()
ElseIf Me.txtOutputFldr.Text = "" Then
MessageBox.Show("Please select an output directory")
Me.btnOutputFldr.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?