-
Timer & Decimal Places
Hi,I am using timer in a form I have to calculate how long a form is open for, so timer when the form is opened, and timer when a button is pressed. I then take the 2nd timer from the first to get the difference. However, it currently shows a few decimal places after the seconds, and ideally I want to get this down so it purely shows whole seconds. Any ideas if this is possible??Also, it would be good to be able to show minutes and seconds, if the number goes above 60, or minutes just as a 0 if this is not possible.Any help appreciated.
We're a Kingdom, and we're United!!
-
I suppose it depends on the format you're dealing with.
Here's an approach using the Date format[VBA]Dim datStart As Date
Private Sub UserForm_Initialize()
datStart = Now()
End Sub
Private Sub cmdStop_Click()
Dim datEnd As Date
Dim datDiff As Long
Dim strResult As String
datEnd = Now()
datDiff = DateDiff("s", datStart, datEnd)
If datDiff > 60 Then
strResult = datDiff \ 60 & "m " & datDiff Mod 60 & "s"
Else
strResult = datDiff & "s"
End If
MsgBox strResult
End Sub[/VBA]
K :-)
-
We're a Kingdom, and we're United!!
-
Or use Format(datDiff, "N:mm"), where N specifies minutes without a leading zero.
Sean.
-
I would use Timer
[vba]
Dim nTime As Double
Private Sub UserForm_Initialize()
nTime = Timer
End Sub
Private Sub cmdStop_Click()
MsgBox Format(Timer - nTime, "0.0 secs")
End Sub
[/vba]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules