Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Calculating times under the second

Hi Everybody!

One question:

I want to calculate the time elapsed from a certain moment, for this purpose
I stored in "A" the value of Now() at the "start" and I read again and
Stored in "B" the value of Now() at the "Stop".

Although I have used the following to format the cell:
Selection.NumberFormat = "mm\:ss.00;@"

in the following statement:
Range("A1")= B-A

I cannot read in A1 any value under the second... how is it possible to
count also that small times?

Thank you for your help

Sergio


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Calculating times under the second

Hi Sergio,

If you're running a PC and not a Mac, then the Timer function should work
for you:

Sub test()
Dim a As Single
Dim b As Single

a = Timer
Application.Wait Now + TimeSerial(0, 0, 5)
b = Timer
Range("A1").Value = b - a
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


SergioBS wrote:
Hi Everybody!

One question:

I want to calculate the time elapsed from a certain moment, for this
purpose I stored in "A" the value of Now() at the "start" and I read
again and Stored in "B" the value of Now() at the "Stop".

Although I have used the following to format the cell:
Selection.NumberFormat = "mm\:ss.00;@"

in the following statement:
Range("A1")= B-A

I cannot read in A1 any value under the second... how is it possible
to count also that small times?

Thank you for your help

Sergio


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 136
Default Calculating times under the second

Jake:
I may be mistaken, but when I first started using Excel 5 under Win
3.11, the now function would capture fractions of a second. It doesn't
now. Do you know when MS changed this?

Jake Marx wrote:

Hi Sergio,

If you're running a PC and not a Mac, then the Timer function should work
for you:

Sub test()
Dim a As Single
Dim b As Single

a = Timer
Application.Wait Now + TimeSerial(0, 0, 5)
b = Timer
Range("A1").Value = b - a
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Calculating times under the second

Hi JWolf,

JWolf wrote:
I may be mistaken, but when I first started using Excel 5 under Win
3.11, the now function would capture fractions of a second. It
doesn't now. Do you know when MS changed this?


I'm not exactly sure when/if this happened. I don't remember Now() ever
having much resolution.

As of now, however, this is how each method stacks up as far as resolution
goes (working from memory here):

Now(), Date(), Time(): about 1 second
Timer, Timer control, GetTickCount API: 10-12ms (15-18 for OSes prior to
NT4)
TimeGetTime API: 1ms
QueryPerformanceCounter API: (almost) limitless

I can't think of too many cases in VBA that you would need anything better
than Timer, but anything's possible I suppose.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Calculating times under the second

Hi Jake!

Thank you!

It still works, but it gives seconds as unit, so I have to divide it by
57600 to have it in the usual format....but I can get 1/1000 seconds!!

Regards

Sergio
"Jake Marx" ha scritto nel messaggio
...
Hi Sergio,

If you're running a PC and not a Mac, then the Timer function should work
for you:

Sub test()
Dim a As Single
Dim b As Single

a = Timer
Application.Wait Now + TimeSerial(0, 0, 5)
b = Timer
Range("A1").Value = b - a
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


SergioBS wrote:
Hi Everybody!

One question:

I want to calculate the time elapsed from a certain moment, for this
purpose I stored in "A" the value of Now() at the "start" and I read
again and Stored in "B" the value of Now() at the "Stop".

Although I have used the following to format the cell:
Selection.NumberFormat = "mm\:ss.00;@"

in the following statement:
Range("A1")= B-A

I cannot read in A1 any value under the second... how is it possible
to count also that small times?

Thank you for your help

Sergio




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
Calculating Times for Pay Rates aussiegirlone[_3_] Excel Discussion (Misc queries) 4 August 26th 09 10:23 AM
Calculating Times Chris waller Excel Discussion (Misc queries) 3 August 11th 09 08:31 PM
calculating pay rates for different times of the day davidesw New Users to Excel 4 November 10th 07 01:58 AM
re calculating numbers to times Hein Excel Discussion (Misc queries) 2 October 3rd 05 08:17 PM
Calculating times gibbylinks Excel Discussion (Misc queries) 4 August 23rd 05 01:27 PM


All times are GMT +1. The time now is 06:32 PM.

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

About Us

"It's about Microsoft Excel"