none
How to trigger events based on Elapsed Time in Seconds & Milliseconds (or tenths of a second at a min) - use GetTickCount API or What? RRS feed

  • Question

  • The Now() function only returns time to the nearest second and Date does not do fractions of a second...

    Need to trigger event then "x" seconds later trigger another event... then "y" seconds after that another... etc 24/7

    The time between each event will be different... from a few seconds to a few minutes...

    The lengths of time are to the nearest millisecond... like 8.576 seconds or 258.372 seconds... etc

    At a minimum we need to be able to control the event triggers to the nearest tenth of a second.

    I understand the GetTickCount API returns milliseconds since the computer was turned on... so monitoring that during the event may be an approach...

    But, I don't know how accurate it is... and maybe there is a better way...

    Thanks for any help on this.

    Tuesday, March 6, 2012 10:54 PM

All replies

  • The VBA function Timer returns the number of seconds since midnight as a Single precision number, with 3 decimal places. However, just as with GetTickCount, the unit is 1 tick = 1/60 second. That should be sufficiently precise for your purpose.

    Regards, Hans Vogelaar

    Tuesday, March 6, 2012 11:33 PM
  • The Now() function only returns time to the nearest second and Date does not do fractions of a second...

    Need to trigger event then "x" seconds later trigger another event... then "y" seconds after that another... etc 24/7

    The time between each event will be different... from a few seconds to a few minutes...

    The lengths of time are to the nearest millisecond... like 8.576 seconds or 258.372 seconds... etc

    At a minimum we need to be able to control the event triggers to the nearest tenth of a second.

    I understand the GetTickCount API returns milliseconds since the computer was turned on... so monitoring that during the event may be an approach...

    But, I don't know how accurate it is... and maybe there is a better way...

    Thanks for any help on this.


    Check out the SetTimer and KillTimer APIs.

    Tushar Mehta (Technology and Operations Consulting)
    www.tushar-mehta.com (Excel and PowerPoint add-ins and tutorials)
    Microsoft MVP Excel 2000-Present

    Friday, March 9, 2012 5:28 AM