Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RichTextBox Sort/Search of a Text File 1

Status
Not open for further replies.

Funkymayo

MIS
Jun 24, 2005
5
US
Over the past couple weeks I've been trying to reaquaint myself with VB.NET. Currently I'm trying to develop a program that will reference the fourth letter (which ranges from numbers 1 to 7) within each line of a RichTextBox and pull the information into another RichTextBox. The idea is to hard code each option, giving seven choices for the user to select from a drop down menu. Using Excel is not an option for at this point because the log that I'm pulling the information from is roughly 500k+ rows.

Primary objectives that I'm trying to gain:

First: Display the original user selected file within RichTextBox1. (This part is completed)

Second: From the user selecting a given option, display the modified information within RichTextBox2.

Sample information to be sorted:

<167>Jul 07 2005 22:58:34: %PIX-7-710005:

<163>Jul 07 2005 22:58:37: %PIX-3-106011:

<164>Jul 07 2005 22:58:37: %PIX-4-106023:

Open File Code:
Code:
Public Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileOpen.Click
        Try
            With OpenDialog1
                
                .Filter = "Text files (*.txt)|*.txt|" & "All files|*.*"
               
                If .ShowDialog() = DialogResult.OK Then
                    FileName = .FileName
                    sr = New StreamReader(.OpenFile)
                    RichTextBox1.Text = sr.ReadToEnd
                End If
            End With
        Catch es As Exception
            MessageBox.Show(es.Message)
        Finally
            If Not (sr Is Nothing) Then
                sr.Close()
            End If
        End Try
    End Sub
I'm sure there has to be a better way to do this, so any advice for the current route that I'm taking, or any suggestions on another way to go are greatly appreciated.
 
Looks like data manipulation to me....
Simply bring your data into a datatable, and then you can sort,filter etc...on any of the fields and post-process it to your hearts content.


Sweep
...if it works dont f*** with it
...if its f****ed blame someone else
...if its your fault that its f***ed, say and admit nothing.
 
<167>Jul 07 2005 22:58:34: %PIX-7-710005:

number - from start till IndexOf(">")
date - from IndexOf(">") count 11 digits (assume the format is "mmm dd yyyy")
time - omitting the space, then next 8 digits is the time (assuming that the format is "hh:mm:ss")
last - from IndexOf("%") till LastIndexOf(":")


This way is of course without using database.

Errr.... why dont you use XML file to store the information ??
 
Sweep,

I agree with the fact that it is just simple data manipulation. Honestly, that's exactly what I was doing before trying to create this program, but doing it all completely manual which took forever because of the large file size. But as far as your suggestion goes, I'm currently scrolling through the message boards on how to do what you are talking about. For whatever reason, I'm having a hard time wrapping my brain around this one.

VBakias,

I now see how to get the reference from the 4th character, but my next question would be how to select the rest of the entry(i.e variable length) to be pulled to the other RichTextBox? But, as far as the XML file as a solution, from what I'm told by my administrator is that it wouldn't be an option.

Thanks to the both of you for taking the time out to help get me on track.
 
If you let me know how you're mapping the data, I'll knock up a few lines to get the file into a datatable.


Sweep
...if it works dont f*** with it
...if its f****ed blame someone else
...if its your fault that its f***ed, say and admit nothing.
 
If I'm understanding correctly, we are using Tab, Space, and "/" as our delimiting values to get the data.
 
Sample data

<167>Jul 07 2005 22:58:34: %PIX-7-710005:
<163>Jul 07 2005 22:58:37: %PIX-3-106011:
<164>Jul 07 2005 22:58:37: %PIX-4-106023:

What are you splitting this into?
eg Record1 (are there 4 elements to this or more??)
167
Jul 07 2005
22:58:34
PIX7-7-710005

Once we know this we can start to help. Its impossible to guess at your data mapping, and what it all means



Sweep
...if it works dont f*** with it
...if its f****ed blame someone else
...if its your fault that its f***ed, say and admit nothing.
 
How you have it split into the 4 elements is great, the only thing I would also need is to have an element that would gather any information past the the last semi-colon.
 
This gives the data after the last ":".
You have to apply this method to a string variable

.Substring(LastIndexOf(":"))
 
SqueakinSweep,
Were you going to create some code for this? I have the same issue as FunkyMayo and I'd rather not start a new thread.

Thanx.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top