Solved

Timer in 1/100 seconds

Posted on 1998-11-15
8
371 Views
Last Modified: 2013-12-25
A timer to display the following time:
12:00:16.15
and refresh every 1/100 seconds.
I made one timer but there is a overhaed of 0.05 to 0.1
second.
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.
0
Comment
Question by:sssssss
8 Comments
 
LVL 2

Expert Comment

by:schild
Comment Utility
this Help page will give you the needed answer:

timeSetEvent
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,          
  LPTIMECALLBACK lpTimeProc,  
  DWORD dwUser,              
  UINT fuEvent                
);
 
Parameters
uDelay
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.
uResolution
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.
lpTimeProc
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.
dwUser
User-supplied callback data.
fuEvent
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.)

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


Good Luck
Schild
0
 

Author Comment

by:sssssss
Comment Utility
Please give an example, the help page is not clear and is not help much
0
 

Author Comment

by:sssssss
Comment Utility
I appreciate an answer with an example.
0
 
LVL 3

Expert Comment

by:OmegaJunior
Comment Utility
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.

Imagine!
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:sssssss
Comment Utility
using the below statement from help of the vb :

Start = Timer
    Do While Timer < Start + PauseTime
       LoopCount = LoopCount + 1
    Loop
    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?
0
 
LVL 14

Expert Comment

by:Matti
Comment Utility
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!

Matti

0
 
LVL 4

Accepted Solution

by:
anzen earned 100 total points
Comment Utility
Get the Hi-Res timer object (OCX) from the C.C.R.P. site
http://www.mvps.org/ccrp it should resolve Your problem

0
 

Author Comment

by:sssssss
Comment Utility
Thanks!
I got what I want.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now