I'm using a progress bar to monitor a process that's retrieving a lot of data from a database. That process loops and updates the ProgressBar.Value property as it goes round.
Problem is, i don't see anything happen. The progress bar is visible and when I step through the code I can see the value changing but nothing gets displayed. I've tried calling the form.refresh function but no banana.
Is there anything else I need to do to get this thing working?
Sorry, you'll have to elaborate, i'm new to VB. Do you mean just putting in idle calculations to take up processor time and give it time to display?
Or do you mean raising an event that causes the bar to refresh?
IT's worth noting that the code that causes the bar to update is in a separate class to the form and calls a sub in the form to get it to update. Coudl this be the cause of my problems? The bar does update itself if I set the value in the form_load function.
I mean putting in idle calculations to take up processor time and give it time to display.
You have to place the code (not the Dim, it goes before) inside the code that loops.
Code:
Dim intCount As Integer
While xxxxx 'Your loop
...
ProgressBar1.Value = ProgressBar1.Value + 1
For intCount = 1 To 100
DoEvents
Next
Me.Refresh
...
Wend
Thanks for the help but still no luck. The progress bar refuses to be updated even though the value is clearly changing and i'm instructing it do do other stuff.
I'm going to try and get it to update from within the form and see what the result is.
I've created a function in the form that does the following
Code:
Public Sub UpdateProgressBar(iValue As Integer)
prgHistoric.Value = iValue
prgHistoric.Refresh
Dim Count As Integer
For Count = 1 To 100
DoEvents
Next
'Me.Refresh
End Sub
If i call this from with form_load and give it a value of 20, then the progressbar loads up already initialised with a value of 20 that you can see.
If i call the function from within another function in a separate class, using the syntax:
Code:
myform.UpdateProgressBar
then nothing happens. Zippo. Progressbar value IS updated but it seems like the screen is not refreshed? I've tried calling both me.refresh and progressbar.refresh
Still nothing, this must be some sort of threading issue that i'm completely unaware of. It's as if the form is running in a completely separate process that's not getting any processor time regardless.
The ProgressBar does not need refresh or doevents.
Ie:
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.