Results 1 to 4 of 4

Thread: Open a File and Looping [Resolved]

  1. #1

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Open a File and Looping [Resolved]

    OK, I know how to get the data out of a file and how to loop to get more than one line. The problem is if the file contains a blank line, my loop stops without continuing. I'm not sure if VB6 had this problem but it is really annoying. I'd also like a .NET answer too please, not an old unmanaged answer if that's what it's called.

    VB Code:
    1. Do While Data <> Nothing 'Problem
    2.     Data = sReader.ReadLine
    3.     ListBox1.Items.Add(Data)
    4. Loop
    Last edited by Ideas Man; Mar 20th, 2004 at 07:56 AM.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    use the while loop on the StreamReader.
    VB Code:
    1. While Not sReader.Peek() = -1
    2.     Data = sReader.ReadLine
    3.     If Not Data = "" Then '/// if there's data in the string.
    4.         ListBox1.Items.Add(Data)
    5.     End If
    6. End While
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718
    OK, I tried that. Firstly, does it matter if you use Do While...Loop instead of While...End While, I didn't notice a difference and second it cuts the last item off in the file, how do you stop that?
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  4. #4

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718
    Sorry, I found out what was wrong, error on my part. Thanks for that, I'm all good now .
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

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