+ Reply to Thread
Results 1 to 3 of 3

Can time be measured to milliseconds?

  1. #1
    Pflugs
    Guest

    Can time be measured to milliseconds?

    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

  2. #2
    RB Smissaert
    Guest

    Re: Can time be measured to milliseconds?

    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" <[email protected]> wrote in message
    news:[email protected]...
    >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



  3. #3
    Pflugs
    Guest

    Re: Can time be measured to milliseconds?

    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" <[email protected]> wrote in message
    > news:[email protected]...
    > >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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1