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

How best to "stack" Hourglass and echos

TheSmileyCoder
Expert Mod 100+
P: 2,321
I have several functions in which I turn on the display of the hourglass when the function starts running and turn it off when complete. That in itself is not a problem.

However sometimes I might reuse that function elsewhere, inside another function in which I also turn on/off the hourglass. This leads to premature turnoff for the hourglass. Its a bit hard to explain, so I will try to illustrate with this example:

Expand|Select|Wrap|Line Numbers
  1. Private Function Main
  2. Docmd.Hourglass True
  3.   Call VeryLongRunningFunction1
  4.   For intI=1 to 100000
  5.     CalculateStuff
  6.   Next intI
  7.  
  8. Docmd.Hourglass false
Now imagine that VeryLongRunningFunction1 takes 2 secs to execute and it is set to turn the hourglass on when it starts and off when it finishes.
Also imagine that the CalculateStuff takes 1 ms to run, so there is no need to turn the hourglass on inside that function, but ofc, running it 100.000 times takes time (10s), and is the reason I used the hourglass in the first place.

Now when the entire Main function runs, the hourglass will only be shown for the first 2 seconds, since Main switches it on, VeryLongRunningFunction1 swithces it on (no difference) and then after running for 2 secs, switching it off, leaving it off for the next 10 secs.

The same type of issues I also have when using Docmd.Echo Off/On
I hope that was explanation enough, and now finally on to the question:

Do you guys have any good method of handling this? I can see several ways of doing this, but I wanted to see if someone allready had thought of a neat way before I start over-complicating things.
Dec 2 '11 #1

✓ answered by NeoPa

NeoPa:
I would have a procedure to manage the states of these objects in your project.

The procedure would manage a static variable as a counter of such requests. Each on request would increment the counter and each off one would decrement it. Any time the counter got below zero it would be reset to zero. Any time the counter reached one after an increment the object should be set (Hourglass shown etc) and any time it reached zero after decrementing from one (IE. Not after going negative) the object should be cleared.

All attempts to manage the object should then be funneled via this procedure. Multiple objects could be managed by the same procedure if required.
I figured you wouldn't need the code done for you Smiley, but then I figured others who read the thread might, so I did one as an example :

Expand|Select|Wrap|Line Numbers
  1. Public Sub SetHourglass(Optional blnSet As Boolean = True)
  2.     Static intCount As Integer
  3.  
  4.     intCount = intCount + IIf(blnSet, 1, -1)
  5.     If intCount = 1 And blnSet Then Call DoCmd.Hourglass(True)
  6.     If intCount = 0 Then Call DoCmd.Hourglass(False)
  7.     If intCount < 0 Then intCount = 0
  8. End Sub

Share this Question
Share on Google+
5 Replies


Expert 100+
P: 446
Hi
Why don't you just call the hourglass again, after VeryLongRunningFunction1 before starting your loop? If your loop is set for only a short run does it matter?

To me, the only important line is to set hourglass false to ensure the user can regain control.
S7
Dec 2 '11 #2

NeoPa
Expert Mod 15k+
P: 31,273
I would have a procedure to manage the states of these objects in your project.

The procedure would manage a static variable as a counter of such requests. Each on request would increment the counter and each off one would decrement it. Any time the counter got below zero it would be reset to zero. Any time the counter reached one after an increment the object should be set (Hourglass shown etc) and any time it reached zero after decrementing from one (IE. Not after going negative) the object should be cleared.

All attempts to manage the object should then be funneled via this procedure. Multiple objects could be managed by the same procedure if required.
Dec 3 '11 #3

NeoPa
Expert Mod 15k+
P: 31,273
NeoPa:
I would have a procedure to manage the states of these objects in your project.

The procedure would manage a static variable as a counter of such requests. Each on request would increment the counter and each off one would decrement it. Any time the counter got below zero it would be reset to zero. Any time the counter reached one after an increment the object should be set (Hourglass shown etc) and any time it reached zero after decrementing from one (IE. Not after going negative) the object should be cleared.

All attempts to manage the object should then be funneled via this procedure. Multiple objects could be managed by the same procedure if required.
I figured you wouldn't need the code done for you Smiley, but then I figured others who read the thread might, so I did one as an example :

Expand|Select|Wrap|Line Numbers
  1. Public Sub SetHourglass(Optional blnSet As Boolean = True)
  2.     Static intCount As Integer
  3.  
  4.     intCount = intCount + IIf(blnSet, 1, -1)
  5.     If intCount = 1 And blnSet Then Call DoCmd.Hourglass(True)
  6.     If intCount = 0 Then Call DoCmd.Hourglass(False)
  7.     If intCount < 0 Then intCount = 0
  8. End Sub
Dec 3 '11 #4

TheSmileyCoder
Expert Mod 100+
P: 2,321
Thank you for that NeoPa. That is actually very much along the lines of my own thinking, but sometimes I find its good to stop, and ask around. I have noticed on occasion that I sometimes over-code something that could have been handled simpler. :)
Dec 4 '11 #5

NeoPa
Expert Mod 15k+
P: 31,273
That makes sense Smiley :-)
Dec 4 '11 #6

Post your reply

Sign in to post your reply or Sign up for a free account.