473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Progressbar

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
4 5755
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Maka Sili | last post by:
Using ProgressBar.Enabled = false does not dim the progress bar. There must be a way. I hope somebody could guide me. Thanks.
2
by: Thomas Kehl | last post by:
Hi! Does anyone have a tipp for me where can I found (or how can I programm) a "progressbar" which has a gradient and the color go from the left side to right and back ... I should have a...
3
by: Steve Teeples | last post by:
Is there a way for code from one class of C# to send a communication to a progressbar in another class to update the bar during runtime? -- Steve
2
by: jez123456 | last post by:
Hi, thanks for the previous advice on progressbars with showing the percentage. I would now like to create a less clunky version. I.e at the moment my progressbar shows 7 separate steps. Some...
8
by: needin4mation | last post by:
Please consider: foreach (ListViewItem item in listViewFiles.Items) { // Display the ProgressBar control. pBar1.Visible = true; // Set Minimum to 1 to represent the first file being copied....
1
by: Mehr H | last post by:
I've been trying to figure out how i can embed a Windows.Forms.ProgressBar in my webform (aspx) file. I have tried putting a Windows.Forms.ProgressBar as public on a regular winform designer form...
3
by: Mitchell Vincent | last post by:
In other programming languages I've been able to easily change the style of a progress bar between smooth and blocked. I find that is either really hidden or impossible in .NET. Am I missing...
1
by: nobody | last post by:
Hi I'm currently developing a Windows application. At the start of the application I load several tables into datatables in a dataset. I also use a progressbar to show the user how much percent...
2
by: =?Utf-8?B?QWFyb24=?= | last post by:
Since some controls such as the DataGridView take a long time to update themselves when performing certain tasks, I have added a StatusStrip with a ProgressBar on it. While I am updating the...
4
by: sivamoorthy | last post by:
how to use a progressbar in a one cpp file but defined in another header file. the function in which i am using is a static member function. how to use the progressbar inside the function ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.