You could also try the following:
myProgressBar.Value = 0
While myStreamReader.Peek <> -1
strLine = myStreamReader.ReadLine()
intPercent = (myStreamReader.BaseStream.Position * 100 ) /
myStreamReader.BaseStream.Length
'Do something with strLine here
'Update the progress bar
myProgressBar.Value += intPercent
End While
I actually tried this and its works fine.
Chris Dunaway wrote:
On 23 Apr 2004 14:30:22 +0200, Shawn wrote:
ProgressBar to the user. I've tried setting
myStreamReader.BaseStream.Seek(0, SeekOrigin.Begin) but
myStreamReader.Peek() just returns -1.
You might try setting the Position property of the base stream to 0:
myStreamReader.BaseStream.Position = 0
I don't know if that will work in this situation though.
Are the lines in the file all the same length? If so, you can get
the number of lines by dividing the length of the file by the line size.
Another method for handling a progress bar is to set the progress bar
with a max value of 100. Then each time you read a line, take the length
of the line and divide it by the length of the file and multiply by 100.
Then increment the progress bar's value by that amount. That way you
don't have to read through every line in the file beforehand:
'This is untested code
myProgressBar.Value = 0
While myStreamReader.Peek <> -1
strLine = myStreamReader.ReadLine()
intPercent = (strLine.Length / myStreamReader.BaseStream.Length) *
100
'Do something with strLine here
'Update the progress bar
myProgressBar.Value += intPercent
End While
Hope this helps a little
--
Chris
To send me an E-mail, remove the underscores and lunchmeat from my
E-Mail address.