Link to home
Start Free TrialLog in
Avatar of Bob Schneider
Bob SchneiderFlag for United States of America

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?
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

I'd use a timer to update a label with the time.
Avatar of Bob Schneider

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
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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!User generated image

If it's a type mismatch, run it through CStr()
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
DateDiff("x", dRaceStart, TimeValue(Now()))

Open in new window

Instead of
Now - dRaceStart

Open in new window

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
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


Open in new window

Thanks so much for all of your help.