Group: microsoft.public.word.vba.general
From: "macropod"
Date: Sunday, April 13, 2008 5:32 PM
Subject: Re: Finding Minutes & Seconds When Using Timer

Hi Steven,

Your code is rounding the number of minutes up. 53818.06 seconds is 896 minutes and 58 seconds. Try:
Sub TestTimer()
Dim tTime As Single
Dim nMinutes As Long
Dim nSeconds As Long
tTime = Timer
nMinutes = Int(tTime / 60)
nSeconds = tTime Mod 60
MsgBox "Timer = " & tTime & vbCrLf _
& nMinutes & " minutes and " & nSeconds & " seconds"
End Sub

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

"StevenM" wrote in message news:BB3A5226-2B71-463E-AAE2-A8FDDA8FCD08@microsoft.com...
> I’ve been using the Timer function to time my macros, but every now and then
> I end up with a negative number when trying to calculate minutes and seconds.
> For example:
>
> Sub TestTimer()
> Dim tTime As Single
> Dim nMinutes As Long
> Dim nSeconds As Long
> tTime = Timer
> nMinutes = CLng(tTime / 60)
> nSeconds = CLng(tTime - (nMinutes * 60))
> MsgBox "Timer = " & tTime & Chr(13) _
> & nMinutes & " minutes and " & nSeconds & " seconds"
> End Sub
>
> One result which I’ve received was:
> "Timer = 53818.06
> 897 minutes and –2 seconds"
>
> 897 minutes is 53820 seconds, just two more than what the Timer gave.
>
> Why do I sometimes get a negative number?
>
> Steven Craig Miller

Safety Articles | Usenet Groups | Usenet News | Bluegrass