Re: How to create two 30 secs delay in 1000 loops routine
The API GetTickCount() sounds like a good candidate to do this. There is still a case where the value will roll back to 0, but it seems appropriate for what you are doing.
Also, be careful with construction like this:
Code:
Do While Timer <> Start
This could lead to an infinite loop, the chances are very small, but I've already seen problem with that kind of validation.
Hope it helps.
JeffB
Re: How to create two 30 secs delay in 1000 loops routine
I think a timer is the best option, a loop will use a lot of CPU and is not needed.
Create a var at the form level and add a timer control to the form
Set the timer interval to 30,000
In the button click add code that sets the var to 0 and enables the timer
In the timer tick event increment the var by 1 and then check to see if the value > 2000. If it is then disable the timer and exit the sub
If not then use the mod function to see if the value is even.
If even run routine 1
Else
Run routine 2
the benifit is that there is no loop running and the CPU will be at 0% usage most of the time where as witht he loop method it will run at 100% even though most of the time it is not doing anythign but looping.
Re: How to create two 30 secs delay in 1000 loops routine
Quote:
Originally Posted by
JeffB
The API
GetTickCount() sounds like a good candidate to do this. There is still a case where the value will roll back to 0, but it seems appropriate for what you are doing.
Also, be careful with construction like this:
Code:
Do While Timer <> Start
This could lead to an infinite loop, the chances are very small, but I've already seen problem with that kind of validation.
Hope it helps.
JeffB
Sigh .. GetTickCount IS WHAT VB timer call is it's just corrected to midnight
And it it is impossible to infinite loop off such a call the modulo restricts the range to valid if you don't understand that then you really shouldnt be offering advice.
Re: How to create two 30 secs delay in 1000 loops routine
Quote:
Originally Posted by
DataMiser
I think a timer is the best option, a loop will use a lot of CPU and is not needed.
Create a var at the form level and add a timer control to the form
Set the timer interval to 30,000
In the button click add code that sets the var to 0 and enables the timer
In the timer tick event increment the var by 1 and then check to see if the value > 2000. If it is then disable the timer and exit the sub
If not then use the mod function to see if the value is even.
If even run routine 1
Else
Run routine 2
the benifit is that there is no loop running and the CPU will be at 0% usage most of the time where as witht he loop method it will run at 100% even though most of the time it is not doing anythign but looping.
Hi DataMiser,
Thanks for the suggestion, from my understanding this will run when the form is load. How about this code to use as command button event? Can you show an example? Sorry I'm still in entry level.
Thanks.
Re: How to create two 30 secs delay in 1000 loops routine
Quote:
Originally Posted by
Uglybb
Sigh .. GetTickCount IS WHAT VB timer call is it's just corrected to midnight
And it it is impossible to infinite loop off such a call the modulo restricts the range to valid if you don't understand that then you really shouldnt be offering advice.
Sigh ... Some people ......
'GetTickCount IS WHAT VB timer call' - Hmm actually it is not ... GetTickcount (MSDN Link), gets the number of ticks from startup from the bios clock, and can rollover to 0 when the bits run out (49.7 days), not when the clock reaches midnight..
VB Timer controls do not CALL gettickcount, but is attached to a hardware timer, and is accurate to 16 ms......
Then .. JeffB is a old time poster here, and is actually a forum Moderator, He got that status by knowing what he's talking about, and giving Good to Excellent advice.. I'd listen to him....
Also DoEvents is one of the most DANGEROUS items to put inside a loop.. Read this MSDN Blog for more info...
Use of Doevents = BAD CODE .....
@UglyBB, Your advice was well aimed but slightly misguided, and it's obvious that you have very little knowledge on the architecture of Windows and VB6, so i'd suggest you bow out of this one...
Quote:
Originally Posted by
ektan
Thanks for the suggestion, from my understanding this will run when the form is load. How about this code to use as command button event? Can you show an example? Sorry I'm still in entry level.
@ektan, Look at the Timers Control article for some sample code on how to properly use timers to complete such tasks.. I'd also recomend the StickFigure animation project from the Animation in VB article on how to use a command button to start it.....
Re: How to create two 30 secs delay in 1000 loops routine
Hi GremlinSA,
Thanks for the advice and guidence on understanding the timer function.
Hi All,
Thanks for the guidence too.
Thanks you very much.