-
Timer at Midnight
This is a simple question. Using Timer, the time resets at midnight. I have tests I want to run for many days. How do I manipulate things so I have the total seconds from when I start over many days? I assume I will have to set some time to 0 on the start click and have a timer updating the date...but I dont know much from there. What do I do?
-
Re: Timer at Midnight
Each days has fixed number of seconds (86400) so you take from there I guess.
This post may interest you.
-
Re: Timer at Midnight
Welcome to VBForums :wave:
Another option is to store the start date & time into a variable, eg:
Code:
Dim datStartedAt as Date
datStartedAt = Now
..and then later you can use DateDiff to find how many seconds there have been since then, eg:
Code:
MsgBox "Seconds since started: " & DateDiff("s", datStartedAt, Now)
While this is simpler, it does have the disadvantage that the timing is only accurate to the nearest second.
-
Re: Timer at Midnight
Welcome Aboard! :wave:
You don't even need a timer control. Set a double precison global variable = to Now when the program commences. Then when the program ends, compare Now to the value of the global variable. You will be accuate to the nearest second, and that should be adequate accuracy for whatever you are doing.
Here's sample code. Build a form with a label and a command button:
Code:
Dim StartTime As Double
Private Sub Command1_Click()
Label1.Caption = "My program ran for " & Format$(Now - StartTime, "hh:mm:ss")
End Sub
Private Sub Form_Load()
StartTime = Now
End Sub