Solved

VB.net Read all lines in a text file

Posted on 2014-04-10
3
917 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

19 Experts available now in Live!

Get 1:1 Help Now