Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. system.io.streamreader.readline

system.io.streamreader.readline

Scheduled Pinned Locked Moved Visual Basic
helpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jayman911
    wrote on last edited by
    #1

    I'm trying to parse a text file using the .readline() method of streamreader. My problem is that my code (below) won't work with text files that have blank lines. It thinks this is an 'end of the file' statement. Is there something else i can test in the conditional statement besides "Do until strLine = Nothing" so that i can read even a blank line and read the file straight through to the 'real' end of file? --------------------------- strLine = srdCurrent.ReadLine() Do Until strLine = Nothing strFile += strLine & CrLf strLine = srdCurrent.ReadLine() Loop ----------------------------

    T 1 Reply Last reply
    0
    • J Jayman911

      I'm trying to parse a text file using the .readline() method of streamreader. My problem is that my code (below) won't work with text files that have blank lines. It thinks this is an 'end of the file' statement. Is there something else i can test in the conditional statement besides "Do until strLine = Nothing" so that i can read even a blank line and read the file straight through to the 'real' end of file? --------------------------- strLine = srdCurrent.ReadLine() Do Until strLine = Nothing strFile += strLine & CrLf strLine = srdCurrent.ReadLine() Loop ----------------------------

      T Offline
      T Offline
      Tom John
      wrote on last edited by
      #2

      Try this example, it reads from a file (including blank lines) into a TextBox: Dim file As New IO.StreamReader("c:\temp\test.txt") While file.Peek > 0 TextBox1.Text += file.ReadLine() & vbCrLf End While file.Close() Hope this helps Tom

      J 1 Reply Last reply
      0
      • T Tom John

        Try this example, it reads from a file (including blank lines) into a TextBox: Dim file As New IO.StreamReader("c:\temp\test.txt") While file.Peek > 0 TextBox1.Text += file.ReadLine() & vbCrLf End While file.Close() Hope this helps Tom

        J Offline
        J Offline
        Jayman911
        wrote on last edited by
        #3

        Hey it worked! Thanks! jaspe

        F 1 Reply Last reply
        0
        • J Jayman911

          Hey it worked! Thanks! jaspe

          F Offline
          F Offline
          Fade Amit BS
          wrote on last edited by
          #4

          i would do it differently, instead of peeking into the file (which is generally not a good thing to do due to various reasons) use this statement instead while MyStramReader.BaseStream.Position < MyStramReader.BaseStream.Length ... should also work faster :) (i think...) Fade (Amit BS)

          J 1 Reply Last reply
          0
          • F Fade Amit BS

            i would do it differently, instead of peeking into the file (which is generally not a good thing to do due to various reasons) use this statement instead while MyStramReader.BaseStream.Position < MyStramReader.BaseStream.Length ... should also work faster :) (i think...) Fade (Amit BS)

            J Offline
            J Offline
            Jayman911
            wrote on last edited by
            #5

            Good suggestion! I'll give it a try, thanks! jaspe

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups