PDA

View Full Version : progress bar is frozen



choubix
06-27-2008, 09:06 PM
hello,

I am running simulations (1from 100 to several 1000) and I use the status bar to display the progression of the process. the code is inside a loop. the status bar shows % but after a while stops incrementing.

the code is this one: (with "counter =1" outside of the loop)


PctDone = Counter / Iterations 'retourne la progression du processus en %
Application.StatusBar = "Portion completed: " & Format(PctDone, "##0.00%")
Counter = Counter + 1

is it possible to avoid having the status bar to freeze. (it freezes randomly: 38%, 70%...)
I thought I could use steps (insted of incremetns of + 1) but if I increment the counter by more than 1 at each iterations it won't be correct...

thanks

Ken Puls
06-27-2008, 09:22 PM
Not an answer, but what version of Excel are you using?

This is a shot in the dark, but you could try resetting the progress bar every 100 entries or so...

If Counter Mod 100 = 0 Then Application.StatusBar = false

choubix
06-27-2008, 09:32 PM
hello Ken Puls,

thanks for taking of your time to answer my question.
I am using Excel 2003.

I tried to use the code like this but it didnt work out


PctDone = Counter / Iterations 'retourne la progression du processus en %
If Counter Mod 100 = 0 Then Application.StatusBar = False
Application.StatusBar = "Portion completed: " & Format(PctDone, "##0.00%")
Counter = Counter + 1
but I thought I could turn the statusbar off by default and turn it back on each time the counter = 5%, 10%, 15% and display the progression in the status bar. problem: I don't get how to code the 5% steps...

Ken Puls
06-27-2008, 10:22 PM
When you say "didn't work out", are you saying that you got an error, or that it ran fine, but still displayed the same issue?

If it ran fine, but displayed the same issue, I doubt that basing it on a % basis will help as the code I gave you would reset the status bar each time the counter hit a multiple of 100.

choubix
06-27-2008, 11:32 PM
hi,

I meant that the status bar was diplaying the same info and was freezing the same way as before

cant figure out to display the info in the status bar every 5% for instance... :(

Ken Puls
06-27-2008, 11:35 PM
Right, that's what I figured. Changing to resetting it based on a % isn't going to make a difference then as a reset is a reset.

I'm not sure why your display would be getting stuck. Have you tried it on another computer?

choubix
06-28-2008, 12:14 AM
yes: same thing.

it's a monte carlo simulation. seems to be pretty intensive...

choubix
06-28-2008, 04:39 AM
I came up with this:

I have: counter = 1 outside the loop

and inside the loop I have this:


PctDone = Iterations * 0.05 'retourne la progression tous les 5%

If i = Counter * PctDone Then
Application.StatusBar = "Simualtions completed: " & Format(Counter * 0.05, "##0.00%")
Counter = Counter + 1
End If

seem to work fine. is the code "clean" o r can i improve it?

Ken Puls
06-28-2008, 08:03 AM
Personally, if it's working I'd leave it alone. I think that any performance gains that you might be able to eek out of it are going to be minimal, at best. It seems pretty streamlined to me.

choubix
06-29-2008, 10:37 PM
thanks ken.
you read my mind: I was thinking "is my code streamlined?" actually.
since i am a beginner I am trying to keep the code as simple as possible (avaiding to create thousands of variables etcetc)