Solved

VB.net Read all lines in a text file

Posted on 2014-04-10
3
897 Views
Last Modified: 2014-04-10
Hi
I have written the following ode to read through a text file
I am missing the looping part to get to the end of the code
What additional code do I need to loop through all the lines of the text file?


   Sub oReadFile(ByVal oTextFilePathAndName As String)
        Try
            Dim oReadLine As String
            Dim oReader As System.IO.StreamReader
            oReader = System.IO.File.OpenText(oTextFilePathAndName)
            With oReader

                oReadLine = .ReadLine

                .Close()
            End With
            oReader = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
0
Comment
Question by:murbro
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39993431
Something like this?
 Sub oReadFile(ByVal oTextFilePathAndName As String)
        Try
            Dim oReadLine As String
            Dim oReader As System.IO.StreamReader
            oReader = System.IO.File.OpenText(oTextFilePathAndName)
            With oReader
            Do
                oReadLine = .ReadLine
            Loop Until oReadLine Is Nothing
                .Close()
            End With
            oReader = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 39993433
Thanks very much
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39993434
Glad I could help!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now