|
-
Mar 20th, 2004, 01:42 AM
#1
Thread Starter
Frenzied Member
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:
Do While Data <> Nothing 'Problem
Data = sReader.ReadLine
ListBox1.Items.Add(Data)
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)
-
Mar 20th, 2004, 06:10 AM
#2
use the while loop on the StreamReader.
VB Code:
While Not sReader.Peek() = -1
Data = sReader.ReadLine
If Not Data = "" Then '/// if there's data in the string.
ListBox1.Items.Add(Data)
End If
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]
-
Mar 20th, 2004, 07:52 AM
#3
Thread Starter
Frenzied Member
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)
-
Mar 20th, 2004, 07:55 AM
#4
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|