-
Aug 23rd, 2011, 12:04 AM
#1
Thread Starter
New Member
-
Aug 23rd, 2011, 12:43 AM
#2
Re: Read Line to Textbox
First things first, StreamReader.ReadLine returns a String, so there's no point calling ToString on the result.
As for the issue, it's important to realise that EVERY time you call ReadLine, you are reading a line. How many times do you call ReadLine in this code:
Code:
If FileReader.ReadLine.ToString.StartsWith("BUT_A") Then txt_A.Text = FileReader.ReadLine()
The answer is twice, therefore you are reading two lines. You are reading a line, checking whether it starts with a particular value and, if it does, you are reading another line and then displaying that second line in the TextBox. You then proceed to do that twice more, so you will be reading anything from three to six lines.
What is it that you are actually trying to do? My guess is that you want to read every line and, for each line, test whether it starts with one of those values and, if it does, display it in the corresponding TextBox. If so the what you need to do is read the line into a variable and then use that variable each time you need that value, not keep reading more lines. Here's a start:
vb.net Code:
Using reader As New IO.StreamReader("file path here") 'Discard the first two lines. For count = 1 To 2 reader.ReadLine() Next Do Until reader.EndOfStream Dim line = reader.ReadLine() 'Use line here, e.g. check what it starts with and display it accordingly. Loop End Using
-
Aug 23rd, 2011, 05:06 AM
#3
Thread Starter
New Member
Re: Read Line to Textbox
Ahh I see! That's much simpler than I thought it would have been.
Thanks a bunch, just used the code and it worked like a charm
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
|