Problem with hundredth of seconds

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

Hello.
I use the following code to get an executing time in cell A1 :

HeureDebut = time()
code......
HeureFin = time()
Duree = HeureFin - HeureDebut
Range("A1").value = Duree

I get numbers such as 0.000173611111111138 in standard number format.
If I use hh:mm:ss.00 as a mask, I dont get but zeroes after the seconds :
00:15:00
I use ROUNDED(0.000173611111111138,6) to get 00:15:03.
This doesn't affect the calculations, only the display.
Why cant Excel use the numbers provided by VBA ?
Thanks in advance.
Daniel
 
Time() returns a number already rounded to seconds.

Try a higher resolution timer via API:


Declare Function timeGetTime Lib "winmm.dll" () As Long

Sub test()
Dim lng As Long

lng = timeGetTime()
Range("A1:IV60000").Value = 1 'example to create delay
lng = timeGetTime() - lng

MsgBox lng & " milliseconds"
End Sub
 
Thanks, Rob, you made it quite clear.
Daniel
Rob van Gelder said:
Time() returns a number already rounded to seconds.

Try a higher resolution timer via API:


Declare Function timeGetTime Lib "winmm.dll" () As Long

Sub test()
Dim lng As Long

lng = timeGetTime()
Range("A1:IV60000").Value = 1 'example to create delay
lng = timeGetTime() - lng

MsgBox lng & " milliseconds"
End Sub
 
Use the following format:
Dim ztime#
ztime = Val(".000173611111111138")
MsgBox Format(ztime, "hh:mm:ss.ss")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top