Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Show Milliseconds

This should write to cells in intervals of 0.125 seconds, and display units
of seconds to 3dp

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

Sub test()
Dim tNow As Long, tNext As Long
Dim tStart As Long
Dim nInterval As Long
Const C As Long = 86400000

With Range("A1:A100")
.Clear
.NumberFormat = "mm:ss.000"
End With

nInterval = 125
tStart = GetTickCount
tNext = tStart

For n = 1 To 17
Cells(n, 1) = (tNext - tStart) / 86400000
tNext = tNext + nInterval
Do While GetTickCount <= tNext
Loop
Next

End Sub

Regards,
Peter T

"Ndel40" wrote in message
...
I am trying to build a program to show elapsed time and I want to display

the
time in "hh:mm:ss.000" format (the worksheet cell is formated as

indicated).
However, I can't get milliseconds to change... always stays at 000.

Here is a test module I am using to try and get the right format... any

help
would be appreciated.

Sub test()
Dim ntime As Date
Dim counter As Integer

counter = 0
Do While counter < 5
ntime = Time
Range("e7").Value = Format(ntime, "hh:mm:ss.000")
counter = counter + 1

MsgBox Format(ntime, "hh:mm:ss.000")
Loop
End Sub

Thanks!




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Show Milliseconds

not quite
?

Why can't I get millisecond results from my VB formula?


The Time function returns whole seconds since midnight

Dim td As Double
td = Time
MsgBox td & vbCr & _
td * 24 * 60 * 60 & vbCr & _
CDate(td)

Regards,
Peter T


"Ndel40" wrote in message
...
So far to the reply's... no, no and not quite, but thanks!

I can get milliseconds to show using standard excel formulas and

formatting
the cell hh:mm:ss.000

Excel Formula...
=TEXT(TIME(18,8,0)-TEXT(NOW(),"hh:mm:ss.000"),"hh:mm:ss.000")

Results in...
10:27:49.580

Why can't I get millisecond results from my VB formula?

ntime = Time
Range("e7").Value = Format(ntime, "hh:mm:ss.000")

OR

StopTime = TimeSerial(15, 15, 15)
myTime = Time
ntime = Format(myTime - StopTime, "hh:mm:ss.000")

Thanks,

Nick



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Show Milliseconds

Thanks!

"Peter T" wrote:

not quite

?

Why can't I get millisecond results from my VB formula?


The Time function returns whole seconds since midnight

Dim td As Double
td = Time
MsgBox td & vbCr & _
td * 24 * 60 * 60 & vbCr & _
CDate(td)

Regards,
Peter T


"Ndel40" wrote in message
...
So far to the reply's... no, no and not quite, but thanks!

I can get milliseconds to show using standard excel formulas and

formatting
the cell hh:mm:ss.000

Excel Formula...
=TEXT(TIME(18,8,0)-TEXT(NOW(),"hh:mm:ss.000"),"hh:mm:ss.000")

Results in...
10:27:49.580

Why can't I get millisecond results from my VB formula?

ntime = Time
Range("e7").Value = Format(ntime, "hh:mm:ss.000")

OR

StopTime = TimeSerial(15, 15, 15)
myTime = Time
ntime = Format(myTime - StopTime, "hh:mm:ss.000")

Thanks,

Nick




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
hh:mm:ss AND Milliseconds? Lainey25 Excel Discussion (Misc queries) 5 May 6th 08 05:32 PM
Show Milliseconds Jim Cone Excel Programming 0 December 28th 06 08:28 PM
Working With Times / Milliseconds Carl Excel Worksheet Functions 1 December 7th 06 05:03 AM
Milliseconds in Excel dhg4 Excel Programming 3 April 12th 05 08:19 PM
Milliseconds In VB ccdubs Excel Programming 1 February 26th 04 11:20 PM


All times are GMT +1. The time now is 11:13 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"