• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Help with issue on Digital Timer VBA Code

Fred Wayne

Member
I have made a digital clock timer. it works perfectly, but I don´t not know why instead of displaying "00:00:00", it displays "12:00:02". This is the code I used:

Code:
Dim dteStart As Date, dteFinish As Date

    Dim dteStopped As Date, dteElapsed As Date

    Dim boolStopPressed As Boolean, boolResetPressed As Boolean

 



Private Sub btnReset_Click()

    dteStopped = 0

    dteStart = 0

    dteElapsed = 0

    Label1 = "00:00:00"

    boolResetPressed = True

End Sub





Private Sub btnStart_Click()

Start_timer:

    dteStart = Time

    boolStopPressed = False

    boolResetPressed = False

Timer_Loop:

    DoEvents

    dteFinish = Time

    dteElapsed = dteFinish - dteStart + dteStopped

    If Not boolStopPressed = True Then

        Label1 = dteElapsed

        If boolResetPressed = True Then GoTo Start_timer

        GoTo Timer_Loop

    Else

        Exit Sub

    End If

End Sub





Private Sub btnStop_Click()

    boolStopPressed = True

    dteStopped = dteElapsed

End Sub





Private Sub CommandButton1_Click()

Unload Me

End Sub





Private Sub UserForm_INITIALIZE()

    Label1 = "00:00:00"

End Sub

I have skimmed from A to Z and can not find out the why it displays in an incorrect way. It supposes to displays the seconds, and then the minutes according to the time running. I would like you to let me if I am doing anything wrong. I have some screenshots and the original file of the Timer. Thank you so much once again in advance.
 

Attachments

  • Capture.JPG
    Capture.JPG
    55.8 KB · Views: 9
  • Capture2.JPG
    Capture2.JPG
    34.3 KB · Views: 9
  • Capture3.JPG
    Capture3.JPG
    158.9 KB · Views: 9
  • Digital Timer.xlsm
    19.3 KB · Views: 9
Last edited by a moderator:
Please use code tag when posting codes in forum. I did it for you this time.
65695

As for your question... In your Sub btn_Start_Click() change the line where you set Label1.
Otherwise, your time is using 12 hour format rather than 24 hour.
Ex:
Code:
       Label1 = Format(dteElapsed, "hh:mm:ss")
 
I have tried:
Label1 = Format(dteElapsed, "hh:mm:ss")
But it does not work. It keeps displaying "12:00:01" when pressing start or reset button.
 
Below is the only change made. Win 10, Office 365.

Code:
Private Sub btnStart_Click()
Start_timer:
    dteStart = Time
    boolStopPressed = False
    boolResetPressed = False
Timer_Loop:
    DoEvents
    dteFinish = Time
    dteElapsed = dteFinish - dteStart + dteStopped
    If Not boolStopPressed = True Then
        Label1 = Format(dteElapsed, "hh:mm:ss")
        If boolResetPressed = True Then GoTo Start_timer
        GoTo Timer_Loop
    Else
        Exit Sub
    End If
End Sub

65718
 
YESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS! YOU ARE AWESOME. EXTRAORDINARY. THANK YOU SO MUCH. YOU ARE THE BEST.
 
Back
Top