Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Grab Time with milliseconds included in VBA

I read one post that had a formula like "=TEXT(NOW(),"SS.00")", that
works, but I can not find anyway to use VBA to include milliseconds in
the time. I have tried worksheets("sheet1").cells(1,1) =
format(Time,"SS.00") and simular code but still can not get vba to
give me the milliseconds.


Thank you,
EKlassen
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Grab Time with milliseconds included in VBA

Search for Sleep

The following

'calls the sleep function and delays macro by 1/2 second
Sleep 500


"Erick" wrote in message
om...
I read one post that had a formula like "=TEXT(NOW(),"SS.00")", that
works, but I can not find anyway to use VBA to include milliseconds in
the time. I have tried worksheets("sheet1").cells(1,1) =
format(Time,"SS.00") and simular code but still can not get vba to
give me the milliseconds.


Thank you,
EKlassen



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Grab Time with milliseconds included in VBA

Hi Erick,

If you are trying to return the time like a stopwatch you could use the
following API which returns the time in milliseconds since system startup:

Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
Sub testTimer()
Dim t As Long
t = GetTickCount

For i = 1 To 1000000
a = a + 1
Next

MsgBox GetTickCount - t, , "Milliseconds"
End Sub

Regards,
Peter

"Erick" wrote in message
om...
I read one post that had a formula like "=TEXT(NOW(),"SS.00")", that
works, but I can not find anyway to use VBA to include milliseconds in
the time. I have tried worksheets("sheet1").cells(1,1) =
format(Time,"SS.00") and simular code but still can not get vba to
give me the milliseconds.


Thank you,
EKlassen



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Grab Time with milliseconds included in VBA

What I am looking for is to get the exact Date and Time down to the
Millisecond when I press a Shortcut Key. Peter, I am not exactly sure
what your code is telling me. It looks like it is timing how long it
takes your code to execute? Every time I run it I get a number in the
msgbox like "1,206,000". Is this supposed to be converting it into
milliseconds with the msgbox? Hmmm?

I decided to use =TEXT(NOW(),"hhmmss.00" formula and refreshing it,
grabbing the value and then putting it where I want it. It seems to
work ok like that. It might not be very accurate? Still more
accurate than me with a stopwatch.

Thank you for the code,
Eklassen



"Peter T" <peter_t@discussions wrote in message ...
Hi Erick,

If you are trying to return the time like a stopwatch you could use the
following API which returns the time in milliseconds since system startup:

Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
Sub testTimer()
Dim t As Long
t = GetTickCount

For i = 1 To 1000000
a = a + 1
Next

MsgBox GetTickCount - t, , "Milliseconds"
End Sub

Regards,
Peter

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Grab Time with milliseconds included in VBA

Hi Erick,

Peter, I am not exactly sure
what your code is telling me.


It should be telling you the time in milliseconds (ms) to run the sample
code, namely the difference in time (ms) between the two calls to the API. I
find this useful for "relative" time comparisons though I'm not sure how
accurate it is purly in terms of ms.

See "High Resolution Timers" at Decision Modals:
http://www.decisionmodels.com/downloads.htm

Also see the VBA's 'Timer' function without using an API. Help says it
records seconds since midnight but it appears to return an extra two decimal
places.

What I am looking for is to get the exact Date and Time down to the
Millisecond when I press a Shortcut Key


I'm not sure a time in ms activated by a human key press would be
meaningful, assuming you have found some way to accurately set the time to
1ms, your system clock keeps accurate time (mine loses 1 min / month) and
the DateTime clock records ms (it doesn't).

Regards,
Peter

"Erick" wrote in message
om...
What I am looking for is to get the exact Date and Time down to the
Millisecond when I press a Shortcut Key. Peter, I am not exactly sure
what your code is telling me. It looks like it is timing how long it
takes your code to execute? Every time I run it I get a number in the
msgbox like "1,206,000". Is this supposed to be converting it into
milliseconds with the msgbox? Hmmm?

I decided to use =TEXT(NOW(),"hhmmss.00" formula and refreshing it,
grabbing the value and then putting it where I want it. It seems to
work ok like that. It might not be very accurate? Still more
accurate than me with a stopwatch.

Thank you for the code,
Eklassen



"Peter T" <peter_t@discussions wrote in message

...
Hi Erick,

If you are trying to return the time like a stopwatch you could use the
following API which returns the time in milliseconds since system

startup:

Public Declare Function GetTickCount Lib "kernel32.dll" () As Long
Sub testTimer()
Dim t As Long
t = GetTickCount

For i = 1 To 1000000
a = a + 1
Next

MsgBox GetTickCount - t, , "Milliseconds"
End Sub

Regards,
Peter



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
charting time series with milliseconds with scatter ecoulson Charts and Charting in Excel 2 December 2nd 09 11:58 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
How to combine milliseconds with date/time reference and display? Bruce Excel Worksheet Functions 5 April 27th 06 07:44 AM
Grab Server Time ianripping[_96_] Excel Programming 1 September 16th 04 08:21 PM


All times are GMT +1. The time now is 09:58 AM.

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"