Timer in 1/100 seconds

Posted on 1998-11-15
Last Modified: 2013-12-25
A timer to display the following time:
and refresh every 1/100 seconds.
I made one timer but there is a overhaed of 0.05 to 0.1
The timer I made was using a timer object, a timer function
and a for loop procedure, but when in run, the unmber
diplay from the screen just not in sequence.
I assume that there could be a better function to solve this problem.
Question by:sssssss

Expert Comment

ID: 1488284
this Help page will give you the needed answer:

The timeSetEvent function starts a specified timer event. The multimedia timer runs in its own thread. After the event is activated, it calls the specified callback function or sets or pulses the specified event object.

MMRESULT timeSetEvent(
  UINT uDelay,                
  UINT uResolution,          
  DWORD dwUser,              
  UINT fuEvent                
Event delay, in milliseconds. If this value is not in the range of the minimum and maximum event delays supported by the timer, the function returns an error.
Resolution of the timer event, in milliseconds. The resolution increases with smaller values; a resolution of 0 indicates periodic events should occur with the greatest possible accuracy. To reduce system overhead, however, you should use the maximum value appropriate for your application.
Address of a callback function that is called once upon expiration of a single event or periodically upon expiration of periodic events. If fuEvent specifies the TIME_CALLBACK_EVENT_SET or TIME_CALLBACK_EVENT_PULSE flag, then the lpTimeProc parameter is interpreted as a handle to an event object. The event will be set or pulsed upon completion of a single event or periodically upon completion of periodic events.
User-supplied callback data.
Timer event type. This parameter may include one of the following values. Value Meaning
TIME_ONESHOT Event occurs once, after uDelay milliseconds.
TIME_PERIODIC Event occurs every uDelay milliseconds.

The fuEvent parameter may also include one of the following values: Value Meaning
TIME_CALLBACK_FUNCTION When the timer expires, Windows calls the function pointed to by the lpTimeProc parameter. This is the default.  
TIME_CALLBACK_EVENT_SET When the timer expires, Windows calls the SetEvent function to set the event pointed to by the lpTimeProc parameter. The dwUser parameter is ignored.  
TIME_CALLBACK_EVENT_PULSE When the timer expires, Windows calls the PulseEvent function to pulse the event pointed to by the lpTimeProc parameter. The dwUser parameter is ignored.  

Return Values
Returns an identifier for the timer event if successful or an error otherwise. This function returns NULL if it fails and the timer event was not created. (This identifier is also passed to the callback function.)

Each call to timeSetEvent for periodic timer events requires a corresponding call to the timeKillEvent function.

Good Luck

Author Comment

ID: 1488285
Please give an example, the help page is not clear and is not help much

Author Comment

ID: 1488286
I appreciate an answer with an example.
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.


Expert Comment

ID: 1488287
Greetings, sssssss,

If you're using the normal timer event, you might want to add the statement "DoEvents" inside every loop and IF-THEN-statement in the code for the timer. It allows the system to perform its normal functions while performing the timer almost at the same time.
Since the typical dos/windows-based pc does not allow multi tasking but only time sharing, you have to tell the system which functions are more serious than others. If you don't, the system will use its time for some other function and cause other functions to flicker. Taking up the "DoEvents" statement will allow the timer events to procede as they are planned: every 1/100 of a second.
Note: be careful with DoEvent! You might come to overuse it, and cause all kinds of unwanted things to happen. For instance: allowing the user to hit any button while a critical function hasn't completed, ensuring that the critical function will erronously complete after the hit instead of correctly before.


Author Comment

ID: 1488288
using the below statement from help of the vb :

Start = Timer
    Do While Timer < Start + PauseTime
       LoopCount = LoopCount + 1
    Finish = Timer
    TotalTime = Finish - Start
    Print TotalTime
    Print LoopCount

result will be the follwing :
PauseTime    TotalTime           Error            LoopCount
    1         1.039 - 1.049     0.039 - 0.049     4401 - 4580
  0.1        0.1099 - 0.1100    0.0099 - 0.01      245 - 452
  0.01       0.0049 - 0.06      0.0051 - 0.05       37 - 231

using this statement, still has 0.05 secound overhead, the smallest pause time
the bigger overhead. And the overhead will become bigger If the result disply from the
label in every loop.
Could this problem be solved?
LVL 14

Expert Comment

ID: 1488289
Try to use API: GetTickCount

It is the best an lowestlevel timer the Windows may offer.

This time scale may recuire a special tuned computer.

For example chache memory speeds up computer, but not all the time, some time there will be mishit and you see it as jump in this timer. Also it is possible the Windows self may want to do
someting during this timing, it may scan network, update display and so on.  
The 0.05 secound overhead will be very difficult to
remove there if you run it on windows.
There is always bossible that some function call hangs on a litle.

To have better precision you may need to use an electronic
measuring instrument in PC slot, these have own sampling systems
independet what is gooing whit Windows.

It is currently regular PC, not a laboratory equipment.

I hope this helps you!



Accepted Solution

anzen earned 100 total points
ID: 1488290
Get the Hi-Res timer object (OCX) from the C.C.R.P. site it should resolve Your problem


Author Comment

ID: 1488291
I got what I want.

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question