Results 1 to 2 of 2

Thread: [2005] The problem of sr.EndOfStream when the last line holds data

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    252

    Question [2005] The problem of sr.EndOfStream when the last line holds data

    Hi,

    When I process a text file, I do so line-by-line using:
    VB Code:
    1. while not sr.EndOfStream
    ...but if the last line of the file contains data (i.e. there are no blank lines at the bottom), the last line doesn't get read. I do a workaround for this by opening up a file, adding a line then opening it up again to process. Pretty bad, huh?!

    So what's the best way to get around the 'last line with data' prob? I suspect it might have something to do with "Peek", which I've never used.

    Thank you!

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] The problem of sr.EndOfStream when the last line holds data

    VB Code:
    1. Do Until Sr.EndOfStream

    Would that change things?

    If not then peek is done like so:
    VB Code:
    1. Do until sr.Peek = -1
    2. msgbox sr.read
    3. Loop
    You have to use Read or ReadLine inside the loop (duh) or else the loop will continue...forever!
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width