473,625 Members | 3,329 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,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?
Nov 6 '07 #1
0 1076

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

Similar topics

39
6043
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 containing norwegian special characters æ, ø and å. >>> liste =
8
3508
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 the moment the printed output is usually going to Word. It's turning into an unholy mess, because I'm having to prepare umpteen different Word templates, and the queries that drive them, depending on what events a course has.
19
25448
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 sort columns based on the column header the user has clicked in both Ascending and Descending formats.
7
4811
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 expandable row, the hidden row is made visible with css. The problem is when i sort the rows, the hidden rows get sorted as well which i don't want and want to be moved (while sorting) relative to their parent rows. The following is my complete html code...
1
4146
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 info to a text file to see what is happening. What I found out is that when I clicked on a column to sort it the Sorting function was continuously being called thus causing the Default Application Pool in IIS to stop. Here is the code I am using
3
22749
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. I turned on the Allow Sorting property but when I click one of the columns that is bound, it will not sort. Below is the code I am using
3
7326
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 uses unfamiliar terms and syntax. Intermediate and advanced Perl coders should find this article useful. The object of the article is to inform the reader, it is not about how to code Perl or how to write good Perl code, but to teach the Schwartzian...
5
4932
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 there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html Here is some jquery js that I think...
0
8256
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8694
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5570
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4193
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.