By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Progressbar

P: n/a
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
Apr 12 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Apr 12, 4:13 pm, "fniles" <fni...@pfmail.comwrote:
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
Apr 12 '07 #2

P: n/a
Thank you.
So, I do not need to do ProgressBar1.PerformStep() anymore (instead replace
that with ProgressBar1.Value = sr.BaseStream.Position) ?
"RickH" <pa******@windcrestsoftware.comwrote in message
news:11*********************@l77g2000hsb.googlegro ups.com...
On Apr 12, 4:13 pm, "fniles" <fni...@pfmail.comwrote:
>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


Apr 13 '07 #3

P: n/a
On Apr 12, 8:57 am, "fniles" <fni...@pfmail.comwrote:
Thank you.
So, I do not need to do ProgressBar1.PerformStep() anymore (instead replace
that with ProgressBar1.Value = sr.BaseStream.Position) ?

"RickH" <passp...@windcrestsoftware.comwrote in message

news:11*********************@l77g2000hsb.googlegro ups.com...
On Apr 12, 4:13 pm, "fniles" <fni...@pfmail.comwrote:
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- Hide quoted text -

- 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
Apr 13 '07 #4

P: n/a
Thank you very much.

"RickH" <pa******@windcrestsoftware.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
On Apr 12, 8:57 am, "fniles" <fni...@pfmail.comwrote:
>Thank you.
So, I do not need to do ProgressBar1.PerformStep() anymore (instead
replace
that with ProgressBar1.Value = sr.BaseStream.Position) ?

"RickH" <passp...@windcrestsoftware.comwrote in message

news:11*********************@l77g2000hsb.googlegr oups.com...
On Apr 12, 4:13 pm, "fniles" <fni...@pfmail.comwrote:
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- Hide quoted text -

- 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


Apr 13 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.