?
Solved

Reading a Text file and  Displaying only certain lines in a Text Box.

Posted on 2006-05-16
6
Medium Priority
?
222 Views
Last Modified: 2012-05-05
Below is a text file I'm making an app to read.  My question is, How do I read only the lines that start with "\\" and place them into a text box.  Also, notice that some of the "\\" lines are the same.  I want to only show ONE instance of each in my text box.  For example, "\\ Member ZBA9 Not Found In Database" should be in my text box only once.  And the other "\\" lines would follow.  Could someone please help me out with the code for this?  I have the skills to read the file and display the whole thing in the text box, but not how to only display certain items.  Thanks!!




\\ Member ZBA9 Not Found In Database
"ZBA9","97301010",-750006,0,-738396,0,-747684,0,-768582,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

\\ Member ZBA9 Not Found In Database
"ZBA9","97301011",750006,0,738396,0,747684,0,768582,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

\\ Member ZBE9 Not Found In Database
"ZBE9","97301030",-3912570,0,-3896316,0,-3880062,0,-3877740,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

\\ Member No OH_HC Parent Not Found In Database
"No OH_HC Parent","E930","No Activity Type",-0.90999999999999992,0,-0.71999999999999997,0,120.35000000000001,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5125.5099999999993,0,0,0

\\ Member L5117 Not Found In Database
"Total DL HC","AT4055","T608      ","L5117",74.967787999999999,1
0
Comment
Question by:Heyitsjoe80
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:wildcard76
ID: 16694099
Hello There,

I would recommend that you read the text file one line at a time, using the .readline method
get this line into a string variable, and use the .Startswith method to determine if it starts with a "//" sequence and add it to your textbox accordingly.

Hope this helps

Best Regards

Cagatay
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16694597
Something like...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fileName As String = "c:\someFile.txt"
        Dim ht As New Hashtable
        Dim line As String
        Dim msg As String
        Dim sr As New System.IO.StreamReader(fileName)
        line = sr.ReadLine
        While Not (line Is Nothing)
            If line.StartsWith("\\") Then
                msg = line.Substring(3)
                If Not ht.ContainsKey(msg) Then
                    ht.Add(msg, Nothing)
                    TextBox1.AppendText(msg & Environment.NewLine)
                End If
            End If
            line = sr.ReadLine
        End While
        sr.Close()
    End Sub
0
 

Author Comment

by:Heyitsjoe80
ID: 16698815
Thanks Idle Mind.  You really got me on the right track!  My boss just asked for one quick edit.  He wants to cut out "\\ Member" and  "Not Found In Database" in each line.

 So it will change from:
\\ Member ZBA9 Not Found In Database
"ZBA9","97301010",-750006,0,-738396,0,-747684,0,-768582,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

To:
ZBA9

I got "\\ Member" gone by just making msg = line.Substring(10), but can't figure out how to get rid of the last part.  When I tried line.replace("Not Found In Database", "") but then \\ Member comes back.  My logic is all screwed up.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 16698844
You can string (no pun intended) functions together:

    msg = line.Substring(10).Replace("Not Found In Database", "").Trim
0
 

Author Comment

by:Heyitsjoe80
ID: 16698863
Didn't even think of that.  Thanks Idle
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16698884
No problem...   =)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question