Solved

VB.net Read all lines in a text file

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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 hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

786 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