473,396 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How best to "stack" Hourglass and echos

TheSmileyCoder
2,322 Expert Mod 2GB
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

5 2610
sierra7
446 Expert 256MB
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
32,556 Expert Mod 16PB
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
32,556 Expert Mod 16PB
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
2,322 Expert Mod 2GB
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
32,556 Expert Mod 16PB
That makes sense Smiley :-)
Dec 4 '11 #6

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

Similar topics

5
by: Al Christoph | last post by:
I have a program that mixes wizard like behavior with random access to the various dialogs in the wizard. I do this by having each step map to a toolstripmenuitem. Users can randomly choose the...
6
by: Generic Usenet Account | last post by:
Is it okay to return a local datastructure (something of type struct) from a function, as long as it does not have any pointer fields? I think it is a bad idea, but one of my colleagues does not...
3
by: babylon | last post by:
any facilities in csharp that can help me implmenting undo/redo in my application? thx
3
by: danavni | last post by:
i need to build a service that will accept incoming TCP/IP connections. the service should act like a "HUB" where on one side clients connect to it and stay connected for as long as they like and...
15
by: Joe Van Dyk | last post by:
Can someone explain what a heap and what a stack is? And why I should care? I used to know, but then I forgot. And I can't seem to find it in the C++ FAQ. I keep reading how allocating from...
8
by: Henrik | last post by:
Hi Is there any way to see what the System process is doing? We have developed an application running at a production site to measure and optimize the production. The application needs to be...
53
by: fdmfdmfdm | last post by:
This is an interview question and I gave out my answer here, could you please check for me? Q. What are the memory allocation for static variable in a function, an automatic variable and global...
94
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock...
9
by: =?utf-8?b?QXNiasO4cm4gU8OmYsO4?= | last post by:
I am replacing a number of functions with macros. Some of these functions "do something" and then return a variable. This behaviour I have found that I can emulate using the comma operator: ...
10
by: Horacius ReX | last post by:
Hi, in some C program I need to port to some architecture, I send to a function the parameter char with predefined values. Inside the function, this data is read and something is calculated. But...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.