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

silly progress bar question

P: n/a
I need to loop a datatable to do some calculation.
I want to use progress bar to show the 'process status'
Must I need to know the datatable size first ? , if there is 1000 records
inside,
I need to set the maximumn of progress bar = 1000 ??
thanks
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Agnes" <ag***@dynamictech.com.hk> wrote in news:eF#91XFiEHA.140
@TK2MSFTNGP12.phx.gbl:
Must I need to know the datatable size first ? , if there is 1000 records
inside,
I need to set the maximumn of progress bar = 1000 ??


Yes if you want an accurate progress bar.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #2

P: n/a
No,

Depends for the steps you take, when you do a step for every 100 it can as
well be 10.

Cor
I need to loop a datatable to do some calculation.
I want to use progress bar to show the 'process status'
Must I need to know the datatable size first ? , if there is 1000 records
inside,
I need to set the maximumn of progress bar = 1000 ??
thanks

Nov 21 '05 #3

P: n/a
* "Agnes" <ag***@dynamictech.com.hk> scripsit:
I need to loop a datatable to do some calculation.
I want to use progress bar to show the 'process status'
Must I need to know the datatable size first ? , if there is 1000 records
inside,
I need to set the maximumn of progress bar = 1000 ??


Yes. Notice that updating the progressbar in every iteration may cause
a lot of drawing overhead in the UI, so updating it every n iterations
may be a better approach ('If LoopCounter Mod 100 = 0 Then
UpdateProgressBar(LoopCounter)', for example).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4

P: n/a
Here is how I like to do it.
Always keep the progress bar a max 100 for percent.
Then in your code, determine the number of records.
Set a variable to keep track of the percentage complete.
Set up a trigger for each percent tick.
Then update the progress bar only when you increment the trigger.
For example:

Dim numItems as Integer
Dim thisItem as Integer
Dim pctTrigger as Integer
Dim thisPct as Integer

numItems = 'Get total number of Items
'Of course, make sure numItems > 0

For ...Item, Do, Loop, etc
'Do work ...
thisItem += 1
thisPct = (thisItem * 100) \ numItems
if thisPct >= pctTrigger then
Call UpdateProgress(thisPct)
Application.DoEvents
pctTrigger += 1
end if
Next item

This way, you only update the progress when necessary.
If you have 100 items, then you get 100 updates.
If you have 1,000,000 items, then you still only get 100 updates (once every
10,000).
Although if you have that many items, you might add an additional rollover
counter for the DoEvents so it happens say every 100 items. That and you would
proly want worker threads anyway.
Pretty much works no matter how many items you have. Since it is an Integer, to
prevent overflows your number of items should be less than about 21.5 million.
But if you have that many to process, then you should be using different methods
anyway.

Gerald

"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:eF***************@TK2MSFTNGP12.phx.gbl...
I need to loop a datatable to do some calculation.
I want to use progress bar to show the 'process status'
Must I need to know the datatable size first ? , if there is 1000 records
inside,
I need to set the maximumn of progress bar = 1000 ??
thanks

Nov 21 '05 #5

P: n/a
Agnes,
In addition to the other comments:
Must I need to know the datatable size first ?
Is this a problem? You can use DataTable.Rows.Count to get the size of the
DataTable.

As the others suggest I would consider only updating the progress bar for
every 100 elements...

Hope this helps
Jay

"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:eF***************@TK2MSFTNGP12.phx.gbl... I need to loop a datatable to do some calculation.
I want to use progress bar to show the 'process status'
Must I need to know the datatable size first ? , if there is 1000 records
inside,
I need to set the maximumn of progress bar = 1000 ??
thanks

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.