469,609 Members | 1,268 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Loop to read file and exit on button click

Hello. I am trying to write a program that continues to read the last
line of a txt file until a stop button is clicked.

while (ContinueLoop == true )
{
while ((LastLine = file.ReadLine()) != null)
{
LastLine = file.ReadLine();
}//while readline

CurrentTime = DateTime.Now;
lblTime.Text = CurrentTime.ToString();
lblCounter.Text = Counter.ToString();
lblTime.Refresh();
lblString.Refresh();
lblCounter.Refresh();
Application.DoEvents();
Counter++;
lblString.Text = LastLine;

} // While do until button pressed

I have two While loop, once running until a stop button is pressed, and
the other running until the end of the file is found and the last value
assigned to a variable. Problem is that the program runs fine the
first time is passes through the loop but then keeps skipping the inner
loop...I placed a watch on "file.readline()" and, once it has completed
the first loop, it says (under the value col of the Watch window)
"function 'file.ReadLine()' evaluated and returned null.

How can I "refresh" 'file.ReadLine()' value so that it doesnt keep the
"null status"

Thanks!

Nov 17 '05 #1
1 3114
have solved my problem - sorry...for anyone elses interest the soln was
:

while (ContinueLoop == true )
{
while ((line) != null)
{
LastLine = line;
line = file.ReadLine();

}//while readline

CurrentTime = DateTime.Now;
lblTime.Text = CurrentTime.ToString();
lblCounter.Text = Counter.ToString();
lblTime.Refresh();
lblString.Refresh();
lblCounter.Refresh();
Application.DoEvents();
Counter++;
lblString.Text = LastLine;
file.Close();
} // While do until button pressed
}

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Microsoft | last post: by
1 post views Thread by jerry | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.