PDA

View Full Version : Assistance With Building Timer to Track Test Runs



chaserankin
02-24-2022, 07:49 PM
Hello everyone. I am trying to build an Access Database to create records each time we run a test case(SimMode) and track how long it takes the SimMode to turn on(AgeIn) and turn off(AgeOut). The issue I am having right now is that I only need/want seconds/milliseconds to be displayed and I feel like I'm hitting a wall :doh:.

So to break it down I have two questions.

1) How can I get my data to store into Access as 00:00.00?

2) How should I go about building this stopwatch/timer?


Ideally I would thrilled if I could control the timer with one button. i.e. MouseClick down to start and MouseClick Up to stop.


Side Note: I'm an absolute amateur but I am desperately trying to improve my skills. (see horrible code below)

Any help would be greatly appreciated

Private Sub Command51_MouseDown()


Dim StartTime As Date
Dim StopTime As Date


StartTime = Now()


Expression.MouseUp


StopTime = Now()


AGEIN = StopTime - StartTime




End Sub

Also tried this one with two buttons. It seems to work down to the second but I would also like the value to be stored as seconds/milliseconds in my database if possible


Private Sub Command51_Click()


AGEIN = Now()

End Sub


Private Sub Command52_Click()


Dim StartTime As Date
Dim NewTime As Date

StartTime = AGEIN

AGEIN = Now() - StartTime

End Sub

SamT
02-25-2022, 06:29 PM
http://www.vbaexpress.com/kb/getarticle.php?kb_id=1068

SamT
02-25-2022, 06:58 PM
Static StartTime As Date


Function AgeIn() As String
If StartIme = 0 Then
StartTime = Now
AgeIn = ""
Else
AgeIn = Format(Now - StartTime, "mm:ss.####)
StartTime = 0
End If
End Function

If AgeIn = "" Then DO Nothing
IF AgeIn = (A value) then that is the process time


Sub StartProcess
ProcessTime = AgeIn 'Starts Timer
'Blah
'Blah
'Blah
End Sub
Sub Process End
'Blah
'Blah
'Blah
Process Time = AgeIn 'This is the Time
End Sub


Sub ReSetAgeIn()
StartTime = ""
EndSub

If you use the MicroTimer, Do the conversions to decimal seconds after reading the value from Access.

arnelgp
02-25-2022, 10:35 PM
sample demo.

chaserankin
02-28-2022, 08:28 PM
Thanks everyone for the help. arnelgp I don't know how you built such a perfect implementation of what I was looking for based off of my weak description. Well done.

arnelgp
02-28-2022, 09:41 PM
:friends: