Visual Basic If statements issues

Associate
Joined
3 Jun 2005
Posts
22
Right here is my issue,

What i want to achieve using streamreader is to read between particular rows in a text file, and only out put the data in between the rows and continue for each item in the document. For example

Text Start
1
2
3
Text End

So i have some code that says if line contains text start then output the code after that until it reads text end. I can get it to either out put the entire document or out put any lines that read text start. Here is my code...

While lineoftext IsNot Nothing
If lineoftext.Contains("Text Start") Then
txtResults.Text = txtResults.Text & srIn.ReadLine & vbNewLine
End If
lineoftext = srIn.ReadLine()
End While

Can anyone see where im going wrong?
 
Where in that code does it say it will stop when it reads Text End?

I think you're going to need two loops - the outer loop will read while it's not end of file, the inner one will do the text start - text end process when text start is hit.
 
Thanks for the response. That's the one thing I'm struggling with, I'm not sure how to stop it when it gets to the text end.

I was hoping that I could write some code that would say

If line of text contains text start, read and output all the data until the line reads text end.

Then I want to loop this until the end of the document
 
My VB's a bit fuzzy, so this probably won't compile - but you might get the gist:

Code:
While lineoftext IsNot Nothing
     If lineoftext.Contains("Text Start") Then
          While IsNot lineoftext.Contains("Text End")
               txtResults.Text = txtResults.Text & srIn.ReadLine & vbNewLine 
               lineoftext = srIn.ReadLine()
          End While
     End If
     lineoftext = srIn.ReadLine()
End While
 
Back
Top Bottom