Bob Schneider
asked on
Dispmay Running Time in VB6 Program
I use a vb6 program to time running races (5k, marathon, etc). We enter the start time in a db. I would like to display the race's running time in the program, updating every second. what's the best way to do that?
I'd use a timer to update a label with the time.
ASKER
That’s what I was thinking but how do I get the timer to start at the TOD from the db and adjust to the exact time elapsed since that time? I know how to get it to update every second.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I’m glad I was able to help.
If you expand the “Full Biography" section of my profile you’ll find links to some articles I’ve written that may interest you.
Marty - Microsoft MVP 2009 to 2017
Experts Exchange Most Valuable Expert (MVE) 2015 and 2017
Experts Exchange Distinguished Expert in Excel 2018 and 2021
Experts Exchange Top Expert Visual Basic Classic 2012 to 2020
Experts Exchange Top Expert VBA 2018 to 2020
If you expand the “Full Biography" section of my profile you’ll find links to some articles I’ve written that may interest you.
Marty - Microsoft MVP 2009 to 2017
Experts Exchange Most Valuable Expert (MVE) 2015 and 2017
Experts Exchange Distinguished Expert in Excel 2018 and 2021
Experts Exchange Top Expert Visual Basic Classic 2012 to 2020
Experts Exchange Top Expert VBA 2018 to 2020
ASKER
I know I closed this but I am getting a type mismatch error. I am attaching a screen shot that shows were the error is coming from and the values I am passing to the function. Is it an AM/PM issue or is it because my start time (which will always be time of day on a 24 hour format) does not have a date attached? Something else?
Thank you!
Thank you!
If it's a type mismatch, run it through CStr()
lblElapsed.Caption = CStr(GetElapsedTimeString(Now - dRaceStart))
lblElapsed.Caption = CStr(GetElapsedTimeString(Now - dRaceStart))
Oh, wait, I see, I think the problem may be that you're subtracting time in your parameter.
I would try
I would try
DateDiff("x", dRaceStart, TimeValue(Now()))
Instead ofNow - dRaceStart
Where "x" is the units you need - presumable seconds, so that would be "s", but if you're looking for minutes, then use the appropriate value. Reference https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/datediff-function
ASKER
Hi all. I was able to resolve this as follows:
Private Sub tmrRaceClock_Timer()
'On Error GoTo ErrorHandler
Dim sngCurrTime As Single, sngRaceTime As Single
sngCurrTime = ConvertToSeconds(Format(CDate(Now - Int(Now)), "HH:mm:ss"))
lblElapsed.Caption = ConvertToMinutes(sngCurrTime - sngRaceStart)
Exit Sub
ErrorHandler:
Beep
ErrorHandler
End Sub
Thanks so much for all of your help.