How best to "stack" Hourglass and echos

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #1

    How best to "stack" Hourglass and echos

    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:

    Code:
    Private Function Main
    Docmd.Hourglass True
      Call VeryLongRunningFunction1
      For intI=1 to 100000
        CalculateStuff
      Next intI
    
    Docmd.Hourglass false
    Now imagine that VeryLongRunning Function1 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, VeryLongRunning Function1 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.
  • sierra7
    Recognized Expert Contributor
    • Sep 2007
    • 446

    #2
    Hi
    Why don't you just call the hourglass again, after VeryLongRunning Function1 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

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      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.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        Originally posted 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 :

        Code:
        Public Sub SetHourglass(Optional blnSet As Boolean = True)
            Static intCount As Integer
        
            intCount = intCount + IIf(blnSet, 1, -1)
            If intCount = 1 And blnSet Then Call DoCmd.Hourglass(True)
            If intCount = 0 Then Call DoCmd.Hourglass(False)
            If intCount < 0 Then intCount = 0
        End Sub
        Last edited by NeoPa; Dec 4 '11, 08:15 PM. Reason: To include post with explanation.

        Comment

        • TheSmileyCoder
          Recognized Expert Moderator Top Contributor
          • Dec 2009
          • 2322

          #5
          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. :)

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            That makes sense Smiley :-)

            Comment

            Working...