473,503 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble Sorting text file

9 New Member
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?
Nov 6 '07 #1
0 1054

Sign in to post your reply or Sign up for a free account.

Similar topics

39
6013
by: Erlend Fuglum | last post by:
Hi everyone, I'm having some trouble sorting lists. I suspect this might have something to do with locale settings and/or character encoding/unicode. Consider the following example, text...
8
3486
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
19
25424
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
7
4796
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
1
4134
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I have a grid view that pulls data from a dbf file. I set the Allow Sorting to true and I put my code in the Sorting event. The problem is that I can't get the sorting to work so I wrote some...
3
22740
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I have a question that maybe somebody can help me out. I have a gridview that is bound to a sqltable, and I have created two template columns. I am having problems getting the sorting to work....
3
7302
KevinADC
by: KevinADC | last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article...
5
4902
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7458
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.