Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1020
  • Last Modified:

VB.net Read all lines in a text file

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
Murray Brown
Asked:
Murray Brown
  • 2
1 Solution
 
Dan CraciunIT ConsultantCommented:
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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
0
 
Dan CraciunIT ConsultantCommented:
Glad I could help!
0

Featured Post

Technology Partners: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now