PC Review


Reply
Thread Tools Rate Thread

Can time be measured to milliseconds?

 
 
=?Utf-8?B?UGZsdWdz?=
Guest
Posts: n/a
 
      22nd Jun 2006
I know you can pause a macro for a certain number of milliseconds using

Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Option Private Module

but I want to know the time between a certain number of iterations. The
code runs too fast per iteration to calculate using seconds, and I can't seem
to figure out how to measure more precisely. My code is as follows:

Function timeRemaining(lastTime, curRow, endRow, cycles)

lastTime = CDbl(lastTime)

Dim timeNow As Double
Dim cyclesLeft As Long
timeNow = CDbl(Time)
cyclesLeft = Int((endRow - curRow) / cycles)

timeRemaining = format(CDate((timeNow - lastTime) * cyclesLeft), "h:mm:ss")

lastTime = CDbl(Time)

End Function

Thanks for your help,
Pflugs
 
Reply With Quote
 
 
 
 
RB Smissaert
Guest
Posts: n/a
 
      22nd Jun 2006
Maybe this is what you want:

Option Explicit
Private lStartTime As Long
Private Declare Function timeGetTime Lib "winmm.dll" () As Long

Sub StartSW()
lStartTime = timeGetTime()
End Sub

Sub StopSW(Optional ByRef strMessage As Variant = "")
MsgBox "Done in " & timeGetTime() - lStartTime & " msecs", , strMessage
End Sub

Sub ForTesting()

Dim i as long

StartSW
For i = 1 to 10000
'testing code
Next
StopSW

End Sub


RBS

"Pflugs" <(E-Mail Removed)> wrote in message
news:038D62E0-8CA7-418D-8A18-(E-Mail Removed)...
>I know you can pause a macro for a certain number of milliseconds using
>
> Public Declare Sub Sleep Lib "kernel32" _
> (ByVal dwMilliseconds As Long)
> Option Private Module
>
> but I want to know the time between a certain number of iterations. The
> code runs too fast per iteration to calculate using seconds, and I can't
> seem
> to figure out how to measure more precisely. My code is as follows:
>
> Function timeRemaining(lastTime, curRow, endRow, cycles)
>
> lastTime = CDbl(lastTime)
>
> Dim timeNow As Double
> Dim cyclesLeft As Long
> timeNow = CDbl(Time)
> cyclesLeft = Int((endRow - curRow) / cycles)
>
> timeRemaining = format(CDate((timeNow - lastTime) * cyclesLeft),
> "h:mm:ss")
>
> lastTime = CDbl(Time)
>
> End Function
>
> Thanks for your help,
> Pflugs


 
Reply With Quote
 
=?Utf-8?B?UGZsdWdz?=
Guest
Posts: n/a
 
      22nd Jun 2006
Yes, that will work well. Thanks very much!

"RB Smissaert" wrote:

> Maybe this is what you want:
>
> Option Explicit
> Private lStartTime As Long
> Private Declare Function timeGetTime Lib "winmm.dll" () As Long
>
> Sub StartSW()
> lStartTime = timeGetTime()
> End Sub
>
> Sub StopSW(Optional ByRef strMessage As Variant = "")
> MsgBox "Done in " & timeGetTime() - lStartTime & " msecs", , strMessage
> End Sub
>
> Sub ForTesting()
>
> Dim i as long
>
> StartSW
> For i = 1 to 10000
> 'testing code
> Next
> StopSW
>
> End Sub
>
>
> RBS
>
> "Pflugs" <(E-Mail Removed)> wrote in message
> news:038D62E0-8CA7-418D-8A18-(E-Mail Removed)...
> >I know you can pause a macro for a certain number of milliseconds using
> >
> > Public Declare Sub Sleep Lib "kernel32" _
> > (ByVal dwMilliseconds As Long)
> > Option Private Module
> >
> > but I want to know the time between a certain number of iterations. The
> > code runs too fast per iteration to calculate using seconds, and I can't
> > seem
> > to figure out how to measure more precisely. My code is as follows:
> >
> > Function timeRemaining(lastTime, curRow, endRow, cycles)
> >
> > lastTime = CDbl(lastTime)
> >
> > Dim timeNow As Double
> > Dim cyclesLeft As Long
> > timeNow = CDbl(Time)
> > cyclesLeft = Int((endRow - curRow) / cycles)
> >
> > timeRemaining = format(CDate((timeNow - lastTime) * cyclesLeft),
> > "h:mm:ss")
> >
> > lastTime = CDbl(Time)
> >
> > End Function
> >
> > Thanks for your help,
> > Pflugs

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Time-scale chart measured in hours & minutes =?Utf-8?B?Sm9obg==?= Microsoft Excel Charting 7 23rd May 2010 07:20 PM
Display time to the milliseconds Patrick C. Simonds Microsoft Excel Discussion 5 29th Oct 2008 05:16 PM
RESTART time - measured notaguru Windows Vista General Discussion 8 17th Sep 2007 05:56 AM
Getting the time down to milliseconds =?Utf-8?B?TmV2aWUgYW5kIFBoaWw=?= Microsoft Access Form Coding 7 2nd Jan 2005 10:21 PM
Time of Day vs Measured Time Jeff Microsoft Excel Misc 6 9th Dec 2003 04:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:13 AM.