Progressbar

  • Thread starter Thread starter fniles
  • Start date Start date
F

fniles

Thank you.
So, I do not need to do ProgressBar1.PerformStep() anymore (instead replace
that with ProgressBar1.Value = sr.BaseStream.Position) ?
 
Thank you very much.

RickH said:
Yes, but remember that the current base stream position may be way
ahead of the current position your application code is at. This is
because the base stream reads the file in buffer blocks, but your app
is reading a line at a time. So what you can do is keep your own
counter of the total number of bytes you've read and use that value to
set the progress bar value.

like this:

dim myCounter as integer = 0
Do While ...
line = sr.ReadLine
myCounter += line.length
...
...
...
ProgressBar1.Value = myCounter
Loop
 
I am using VS 2005.
I read a file using streamreader.
I want to set the progressbar based on where I am in the file. How can I do
that ?
Thank you.

sr = New StreamReader(sFileName)
line = sr.ReadLine
ProgressBar1.Maximum = 800 --> how to set the maximum property without
reading the whole file first ?
ProgressBar1.Minimum = 0
ProgressBar1.Step = 1
ProgressBar1.Value = 0
Do While line <> Nothing
ProgressBar1.PerformStep()
:
line = sr.ReadLine
Loop
 
I am using VS 2005.
I read a file using streamreader.
I want to set the progressbar based on where I am in the file. How can I do
that ?
Thank you.

sr = New StreamReader(sFileName)
line = sr.ReadLine
ProgressBar1.Maximum = 800 --> how to set the maximum property without
reading the whole file first ?
ProgressBar1.Minimum = 0
ProgressBar1.Step = 1
ProgressBar1.Value = 0
Do While line <> Nothing
ProgressBar1.PerformStep()
:
line = sr.ReadLine
Loop


Before entering your read loop grab the length of the file using
FileInfo:

Dim fi As FileInfo = New FileInfo(sFileName)
ProgressBar1.Maximum = fi.Length
ProgressBar1.Minimum = 0

Once minimum and Maximum are set then just then just keep track of
your bytes read count and each time through the loop set the progress
Value property

Do While ...
line = sr.ReadLine
....
....
....
ProgressBar1.Value = sr.BaseStream.Position
Loop
 
Thank you.
So, I do not need to do ProgressBar1.PerformStep() anymore (instead replace
that with ProgressBar1.Value = sr.BaseStream.Position) ?










- Show quoted text -

Yes, but remember that the current base stream position may be way
ahead of the current position your application code is at. This is
because the base stream reads the file in buffer blocks, but your app
is reading a line at a time. So what you can do is keep your own
counter of the total number of bytes you've read and use that value to
set the progress bar value.

like this:

dim myCounter as integer = 0
Do While ...
line = sr.ReadLine
myCounter += line.length
...
...
...
ProgressBar1.Value = myCounter
Loop
 
Back
Top