Results 1 to 8 of 8

Thread: [RESOLVED] Running Stopwatch with Date & Time

  1. #1

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Resolved [RESOLVED] Running Stopwatch with Date & Time


    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
    any info would be greatly appreciated
    So far I have txtDate & TxtTime set to systemtime
    VB Code:
    1. Private Sub Timer1_Timer()
    2.     txtDate = Date
    3.     txtTime = Time
    4. End Sub
    5.  
    6. Private Sub Form_Load()
    7.     Timer1.Enabled = True
    8.     EmpClock.Enabled = True
    9. 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:
    1. Dim hour As Single
    2. Dim min As Single
    3. Dim sec As Single
    4.  
    5. Private Sub cmdStart_click()
    6. EmpClock.Interval = 1000
    7. 'Need Something to Help Start timer off current time txtTime and place into txtStart
    8. End Sub
    9.  
    10. Private Sub cmdStop_Click()
    11. '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
    12. End Sub
    13.  
    14. Private Sub EmpClock_Timer()
    15.  
    16. If min = 60 Then hour = hour + 1: min = 0
    17. If sec = 60 Then min = min + 1: sec = 0
    18.  
    19. txtStart.Text = Format(Str(hour), "00") & ":" & _
    20. Format(Str(min), "00") & ":" & _
    21. Format(Str(sec), "00")
    22. txtStop.Text = Format(Str(hour), "00") & ":" & _
    23. Format(Str(min), "00") & ":" & _
    24. Format(Str(sec), "00")
    25. txtTotal.Text = Format(Str(hour), "00") & ":" & _
    26. Format(Str(min), "00") & ":" & _
    27. Format(Str(sec), "00")
    28. End Sub
    29. Private Sub cmdReset_Click()
    30. txtStart.Text = "00.00.00"
    31. txtStop.Text = "00.00.00"
    32. txtTotal.Text = "00.00.00"
    33. hour = 0
    34. min = 0
    35. sec = 0
    36. End Sub

    thanks for any help on this
    Last edited by Quizton; Jan 24th, 2006 at 02:41 PM.

  2. #2
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Running Stopwatch with Date & Time

    VB Code:
    1. Option Explicit
    2. Dim StartTime As Date
    3. Dim StopTime As Date
    4.  
    5. Private Sub cmdStart_Click()
    6.     StartTime = Time
    7.     Timer1.Interval = 1000
    8.     Timer1.Enabled = True
    9. End Sub
    10.  
    11. Private Sub cmdStop_Click()
    12.     StopTime = Time
    13.     Timer1.Enabled = False
    14.     Label1 = Format(StopTime - StartTime, "hh:mm:ss")
    15. End Sub
    16.  
    17. Private Sub Timer1_Timer()
    18.     Label1 = Format(Time - StartTime, "hh:mm:ss")
    19. End Sub

  3. #3
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Running Stopwatch with Date & Time

    Did you see how I did it in the reply above?

  4. #4

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    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

  5. #5
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Running Stopwatch with Date & Time

    Take all references to Timer1 out of my code and you will see that it works for you.

  6. #6

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    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
    Last edited by Quizton; Jan 24th, 2006 at 10:30 PM.

  7. #7
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Running Stopwatch with Date & Time

    store the times in variables as I did not in text boxes

  8. #8

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: Running Stopwatch with Date & Time

    Ahaaa Well That was plainly overlooked lol ok well thanks Moeur for the help 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:
    1. Dim StartTime As Date
    2. Dim StopTime As Date
    3. Private Sub cmdLogin_Click()
    4. txtStart.Text = Time
    5. StartTime = Time
    6. End Sub
    7.  
    8. Private Sub cmdLogout_Click()
    9. txtStop.Text = Time
    10. StopTime = Time
    11. txtTotal.Text = Format(StopTime - StartTime, "hh:mm:ss")
    12. End Sub

    Works Like A Charm Thread Resolved to Moeur

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width