Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Gum Gum is offline
external usenet poster
 
Posts: 30
Default VBA adding time in milliseconds

I have this:
Now() is current time.

Function myTime()
Dim t As Variant
t = Now() + TimeValue("00:00:20")
myTime= Format(t, "hh:mm:ss") & "." & Right(Format(Timer, "#0.00"), 2)
End Function

This adds 20 seconds to now()

I require to add milliseconds to Now() rather than seconds to get mytime().
How can this be done?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default VBA adding time in milliseconds

One second as a fraction of a day is
1/(24-60*60)
so for milliseconds divide by another 1000

Be aware though that accuracy to that degree will not be stored in a 'Date'
variable, also the Now function only returns the time to an accuracy one
second.

Depending on what you are doing, eg looking for some sort of timer, there
are different approaches.

Regards,
Peter T



"Gum" wrote in message
...
I have this:
Now() is current time.

Function myTime()
Dim t As Variant
t = Now() + TimeValue("00:00:20")
myTime= Format(t, "hh:mm:ss") & "." & Right(Format(Timer, "#0.00"), 2)
End Function

This adds 20 seconds to now()

I require to add milliseconds to Now() rather than seconds to get
mytime().
How can this be done?



  #3   Report Post  
Posted to microsoft.public.excel.programming
Gum Gum is offline
external usenet poster
 
Posts: 30
Default VBA adding time in milliseconds

A type of timer where the instance of an event is captured, say t and after t
+ Delta t, where deta t is a in milliseconds, an event is triggered. So I
will use a comparator:
if time t plus delta t time t Then
triggerevent
....
if now() is an approximation to the nearest second, I can see the problem
with my formulation. I am also looking for a solution with the minimum
footprint.

"Peter T" wrote:

One second as a fraction of a day is
1/(24-60*60)
so for milliseconds divide by another 1000

Be aware though that accuracy to that degree will not be stored in a 'Date'
variable, also the Now function only returns the time to an accuracy one
second.

Depending on what you are doing, eg looking for some sort of timer, there
are different approaches.

Regards,
Peter T



"Gum" wrote in message
...
I have this:
Now() is current time.

Function myTime()
Dim t As Variant
t = Now() + TimeValue("00:00:20")
myTime= Format(t, "hh:mm:ss") & "." & Right(Format(Timer, "#0.00"), 2)
End Function

This adds 20 seconds to now()

I require to add milliseconds to Now() rather than seconds to get
mytime().
How can this be done?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default VBA adding time in milliseconds

Not sure I quite understand how you intend to implement but here are a
couple of ideas for a timer

Public Declare Function GetTickCount Lib "kernel32.dll" () As Long

Sub test()
Dim t As Single
Dim m As Long

t = Timer ' seconds
m = GetTickCount ' milliseconds

Range("A1:B1") = 123
For i = 1 To 40000
x = Range("a1") + Range("b1")
Next

t = Timer - t
m = GetTickCount - m

Debug.Print t, m

End Sub


The Gettickcount API returns milliseconds since the computer was turned on,
allowing for the overhead of calling the function consider it is accurate to
say better than 1/100th sec', considerably more accurate than Timer
function.

The Timer function returns seconds since midnight and updates about 18 times
/ second. That's enough for many purposes but note it resets at midnight.

There are other more accurate API methods but one of the above should be
sufficient for most purposes.

Regards,
Peter T

"Gum" wrote in message
...
A type of timer where the instance of an event is captured, say t and after
t
+ Delta t, where deta t is a in milliseconds, an event is triggered. So I
will use a comparator:
if time t plus delta t time t Then
triggerevent
...
if now() is an approximation to the nearest second, I can see the problem
with my formulation. I am also looking for a solution with the minimum
footprint.

"Peter T" wrote:

One second as a fraction of a day is
1/(24-60*60)
so for milliseconds divide by another 1000

Be aware though that accuracy to that degree will not be stored in a
'Date'
variable, also the Now function only returns the time to an accuracy one
second.

Depending on what you are doing, eg looking for some sort of timer, there
are different approaches.

Regards,
Peter T



"Gum" wrote in message
...
I have this:
Now() is current time.

Function myTime()
Dim t As Variant
t = Now() + TimeValue("00:00:20")
myTime= Format(t, "hh:mm:ss") & "." & Right(Format(Timer, "#0.00"), 2)
End Function

This adds 20 seconds to now()

I require to add milliseconds to Now() rather than seconds to get
mytime().
How can this be done?






  #5   Report Post  
Posted to microsoft.public.excel.programming
Gum Gum is offline
external usenet poster
 
Posts: 30
Default VBA adding time in milliseconds

I used Timer previously and was thinking of writing a routine to adjust for
that Midnight reset, so the GetTickCount will address that problem too. Your
explanation of the code is quite invaluable.

"Peter T" wrote:

Not sure I quite understand how you intend to implement but here are a
couple of ideas for a timer

Public Declare Function GetTickCount Lib "kernel32.dll" () As Long

Sub test()
Dim t As Single
Dim m As Long

t = Timer ' seconds
m = GetTickCount ' milliseconds

Range("A1:B1") = 123
For i = 1 To 40000
x = Range("a1") + Range("b1")
Next

t = Timer - t
m = GetTickCount - m

Debug.Print t, m

End Sub


The Gettickcount API returns milliseconds since the computer was turned on,
allowing for the overhead of calling the function consider it is accurate to
say better than 1/100th sec', considerably more accurate than Timer
function.

The Timer function returns seconds since midnight and updates about 18 times
/ second. That's enough for many purposes but note it resets at midnight.

There are other more accurate API methods but one of the above should be
sufficient for most purposes.

Regards,
Peter T

"Gum" wrote in message
...
A type of timer where the instance of an event is captured, say t and after
t
+ Delta t, where deta t is a in milliseconds, an event is triggered. So I
will use a comparator:
if time t plus delta t time t Then
triggerevent
...
if now() is an approximation to the nearest second, I can see the problem
with my formulation. I am also looking for a solution with the minimum
footprint.

"Peter T" wrote:

One second as a fraction of a day is
1/(24-60*60)
so for milliseconds divide by another 1000

Be aware though that accuracy to that degree will not be stored in a
'Date'
variable, also the Now function only returns the time to an accuracy one
second.

Depending on what you are doing, eg looking for some sort of timer, there
are different approaches.

Regards,
Peter T



"Gum" wrote in message
...
I have this:
Now() is current time.

Function myTime()
Dim t As Variant
t = Now() + TimeValue("00:00:20")
myTime= Format(t, "hh:mm:ss") & "." & Right(Format(Timer, "#0.00"), 2)
End Function

This adds 20 seconds to now()

I require to add milliseconds to Now() rather than seconds to get
mytime().
How can this be done?







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding and Subtracting a Time with MilliSeconds carl Excel Worksheet Functions 8 April 5th 23 02:41 PM
Time milliseconds format Kaykayme Excel Programming 6 October 29th 08 05:44 PM
Comparing time values which have milliseconds in them e.g 10:20:30 Jon Stickings Excel Discussion (Misc queries) 5 October 5th 06 02:03 PM
Can time be measured to milliseconds? Pflugs Excel Programming 2 June 22nd 06 12:40 AM
Grab Time with milliseconds included in VBA Erick Excel Programming 4 October 28th 04 10:42 AM


All times are GMT +1. The time now is 07:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"