Timer

Solved
le meruvien Posted messages 1414 Status Member -  
le meruvien Posted messages 1414 Status Member -
Hello,
I would like to create a simple form with a "minute" and "second" field that starts at zero as soon as the form is opened (and a reset button).
Thank you

Configuration: Windows / Chrome 79.0.3945.117

5 answers

  1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   Ambassadeur 1 588
     
    Hello,
    this can be done by using the TimerInterval property of the form and the Timer event of the form.
    Private Sub Form_Load() Me.TimerInterval = 1000 'triggers every second End Sub Private Sub Form_Timer() 'modifies the timer display End Sub
    0
  2. le meruvien Posted messages 1414 Status Member 44
     
    Thank you yg-be, but where do I put all this??
    0
    1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588
       
      Could you share your file, containing in the form the fields to display the timer, and a button intended for resetting it?
      0
  3. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   Ambassadeur 1 588
     
    Here is an example of code to include in the form code, with a button called zero and a label called timer.
    Option Compare Database Option Explicit Dim start As Date Private Sub Form_Load() start = Now() display_timer Me.TimerInterval = 1000 End Sub Private Sub form_timer() display_timer End Sub Private Sub zero_Click() start = Now() display_timer End Sub Private Sub display_timer() Dim duration As Date, minutes As Long, seconds As Integer duration = Now() - start minutes = Int(duration * 24 * 60) seconds = (duration * 24 * 60 - minutes) * 60 Me.timer.Caption = CStr(minutes) + "min " + CStr(seconds) + "sec" End Sub
    0
  4. le meruvien Posted messages 1414 Status Member 44
     
    well, it's not working!!
    I've attached my file, you can take a look.
    https://www.cjoint.com/c/JAmoybwaIOd
    thank you
    0
    1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588
       
      As the error message you received indicates, you have two lines with Option Compare Database; you need to remove one of them.
      I also see that you haven't called the zero button. You need to either rename the button or adjust line 12 of the code.
      0
  5. le meruvien Posted messages 1414 Status Member 44
     
    Hello, and a big THANK YOU!! It works!!
    0