[RESOLVED] Running Stopwatch with Date & Time
:bigyello:
Hello All,
I am working on a stopwatch program to record times for various job's
and am having trouble setting the start and stop to count off the date & Time :confused:
any info would be greatly appreciated :thumb:
So far I have txtDate & TxtTime set to systemtime
VB Code:
Private Sub Timer1_Timer()
txtDate = Date
txtTime = Time
End Sub
Private Sub Form_Load()
Timer1.Enabled = True
EmpClock.Enabled = True
End Sub
and then I am usin cmdStart & cmd Stop
and txtStart , txtStop, & txtTotal wich will be of course txtstarttime + txtstoptime
the issue is setting start & stop off the txtTime
this is what ive got on this part so far
VB Code:
Dim hour As Single
Dim min As Single
Dim sec As Single
Private Sub cmdStart_click()
EmpClock.Interval = 1000
'Need Something to Help Start timer off current time txtTime and place into txtStart
End Sub
Private Sub cmdStop_Click()
'Need Something to Help Stop Timer and take current time & place into txtStop then I should be able to find the difference and place into txtTotal
End Sub
Private Sub EmpClock_Timer()
If min = 60 Then hour = hour + 1: min = 0
If sec = 60 Then min = min + 1: sec = 0
txtStart.Text = Format(Str(hour), "00") & ":" & _
Format(Str(min), "00") & ":" & _
Format(Str(sec), "00")
txtStop.Text = Format(Str(hour), "00") & ":" & _
Format(Str(min), "00") & ":" & _
Format(Str(sec), "00")
txtTotal.Text = Format(Str(hour), "00") & ":" & _
Format(Str(min), "00") & ":" & _
Format(Str(sec), "00")
End Sub
Private Sub cmdReset_Click()
txtStart.Text = "00.00.00"
txtStop.Text = "00.00.00"
txtTotal.Text = "00.00.00"
hour = 0
min = 0
sec = 0
End Sub
thanks for any help on this :thumb:
Re: Running Stopwatch with Date & Time
VB Code:
Option Explicit
Dim StartTime As Date
Dim StopTime As Date
Private Sub cmdStart_Click()
StartTime = Time
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub cmdStop_Click()
StopTime = Time
Timer1.Enabled = False
Label1 = Format(StopTime - StartTime, "hh:mm:ss")
End Sub
Private Sub Timer1_Timer()
Label1 = Format(Time - StartTime, "hh:mm:ss")
End Sub
Re: Running Stopwatch with Date & Time
Did you see how I did it in the reply above?
Re: Running Stopwatch with Date & Time
Yes I seen that way as well, But now have done away with the other timer since it really doesnt need to be there since All I am trying to do is get the diff between my current start time and the endtime
txtTotal.Text = txtStop.Text - txtStart.Text
this didnt work and I tried to use this part of your code here
Label1 = Format(StopTime - StartTime, "hh:mm:ss")
and got 00:00:00 for the diff
Not that your code doesnt work as a stopwatch but now all I need is a timediff instead of the whole stopwatch scenario
thanks though and I rated your post as helpful since it will indeed help with another Part of app I workin on ;)
Re: Running Stopwatch with Date & Time
Take all references to Timer1 out of my code and you will see that it works for you.
Re: Running Stopwatch with Date & Time
Private Sub cmdLogout_Click()
txtStop.Text = Time
txtTotal = Format(StopTime - StartTime, "hh:mm:ss")
still getting a 00:00:00 for time diff ?
strange this is not working I must be overlooking something
Re: Running Stopwatch with Date & Time
store the times in variables as I did not in text boxes
Re: Running Stopwatch with Date & Time
Ahaaa Well That was plainly overlooked lol ok well thanks Moeur for the help :thumb: you were right on the money w that one so here is what I came up with to record these times as well as get the diff
thanks again
VB Code:
Dim StartTime As Date
Dim StopTime As Date
Private Sub cmdLogin_Click()
txtStart.Text = Time
StartTime = Time
End Sub
Private Sub cmdLogout_Click()
txtStop.Text = Time
StopTime = Time
txtTotal.Text = Format(StopTime - StartTime, "hh:mm:ss")
End Sub
Works Like A Charm Thread Resolved :thumb: to Moeur