Results 1 to 4 of 4

Thread: [RESOLVED] [2005] Io.streamreader

  1. #1

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Resolved [RESOLVED] [2005] Io.streamreader

    I'm reading a text file through a streamreader. Does the streamreader have something like a "number of lines in file" property, or do I just have to loop until the eof? Thanks.

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: [2005] Io.streamreader

    VB Code:
    1. Debug.Print(ioReader.ReadToEnd.Split(CChar(Environment.NewLine)).GetUpperBound(0).ToString)

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Io.streamreader

    A StreamReader is a forward-only stream. This means it has no idea what data is available on the stream until it reads it, but once it has read it it cannot go back and read it again. Remix's code will give you the number of lines (or actually one less than the number of lines) but, as you see, it has to read the entire file to get that information. There is no way to, for instance, only read the file if it is greater than a certain length. You must read the whole file to determine that length.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: [2005] Io.streamreader

    Ok, thanks.
    Last edited by Nove; Apr 12th, 2006 at 08:41 PM.

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