Setting Timer/Clock Precision

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2005
Posts: 5
Reputation: tony mcquaid is an unknown quantity at this point 
Solved Threads: 0
tony mcquaid tony mcquaid is offline Offline
Newbie Poster

Setting Timer/Clock Precision

 
0
  #1
Jul 21st, 2005
Hey there!

I'm making a break timing device for work (so I can be more aware of how long I'm taking on my breaks. I'm bad at keeping track.) If someone could help me out, it would be greatly appreciated.

What the program does:
- After I click "break" it Counts down from 15 minutes.
- Once the timer hits zero, it counts back up (in red text)

What I Need:
- As of right now, it just tells me how many minutes are left. I need to find out if/how I can display it by the second. (example: 15:00, 14:59, 14:58, 14:57, etc. right down to 0:00. Instead of just "15 Minutes, 14 minutes, etc) How would I do this??

This is the code I have so far:
Option Explicit

Dim StartTime As Date
Dim BreakTime As Long

Private Sub cmdBreak_Click()
cmdbreak.Enabled = False
cmdImBack.Enabled = True

StartTime = Now()
BreakTime = 1

Timer1.Enabled = False
Timer1.Interval = 5000
Timer1.Enabled = True
Timer1_Timer
End Sub

Private Sub cmdImBack_Click()
cmdImBack.Enabled = False
Timer1.Enabled = False
cmdbreak.Enabled = True
Text1.Text = ""

End Sub

Private Sub Form_Load()
cmdbreak.Enabled = True
cmdImBack.Enabled = False
Text1.Text = ""
End Sub

Private Sub Timer1_Timer()

Dim MinutesGone As Long
MinutesGone = DateDiff("n", StartTime, Now())
If MinutesGone < BreakTime Then
With Text1
.Text = (BreakTime - MinutesGone) & _
" mins"
.ForeColor = vbBlack
End With
Else
With Text1
.Text = "-" & (MinutesGone - BreakTime)
.ForeColor = vbRed
End With
End If

End Sub
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Setting Timer/Clock Precision

 
0
  #2
Jul 22nd, 2005
what you do, is set the timer's interval to 1 second. Then use a variable to keep track of the minutes (start at 0, and add 1 to the variable every time the timer fires, then, if the variable is equal to 59 [0-59 is 60 seconds], then reset the variable back to 0, and add 1 to your "minute" count). This will let you keep track of the program down to the seconds, and will still keep the integrity of the minutes... if you need more in-depth help, attach the project in a .zip file, and I'll gladly fiddle with your code.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 5
Reputation: tony mcquaid is an unknown quantity at this point 
Solved Threads: 0
tony mcquaid tony mcquaid is offline Offline
Newbie Poster

Re: Setting Timer/Clock Precision

 
0
  #3
Jul 24th, 2005
Hey there!

My program lists the seconds, but turns red at the wrong time and stuff. Any fiddling you could do with this code would be amazing.

I've emailed you the entire project file to your: fiedler231 hotmail address. Title: "Tony Project"

Thank you so much for your help.
-Tony
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Setting Timer/Clock Precision

 
0
  #4
Jul 26th, 2005
I'm sorry, I never recieved the e-mail. If you could post it here as a .zip attachment, that would be great.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 5
Reputation: tony mcquaid is an unknown quantity at this point 
Solved Threads: 0
tony mcquaid tony mcquaid is offline Offline
Newbie Poster

Re: Setting Timer/Clock Precision

 
0
  #5
Jul 27th, 2005
Here you go

Thanks a million,
-Tony
Attached Files
File Type: zip tonyproject.zip (6.7 KB, 11 views)
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: Setting Timer/Clock Precision

 
0
  #6
Jul 28th, 2005
hey Coma, long time no see! how are you.

and about code, I have change some of your code, i make it simple as possible and work very fine too.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Dim SecLeft As Integer
  4. Dim MinLeft As Integer
  5.  
  6. Private Sub cmdBreak_Click()
  7. cmdbreak.Enabled = False ' To stop them resetting !
  8. cmdImBack.Enabled = True
  9.  
  10. MinLeft = 15
  11. SecLeft = 0
  12.  
  13. Timer1.Enabled = True
  14. Timer1_Timer ' to draw it once!
  15.  
  16. End Sub
  17.  
  18. Private Sub cmdImBack_Click()
  19.  
  20. cmdImBack.Enabled = False
  21. Timer1.Enabled = False
  22. cmdbreak.Enabled = True
  23. Text1.Text = "--"
  24.  
  25. End Sub
  26.  
  27. Private Sub Form_Load()
  28.  
  29. Timer1.Enabled = False
  30. Timer1.Interval = 1000
  31.  
  32. cmdbreak.Enabled = True
  33. cmdImBack.Enabled = False
  34. Text1.Text = "--"
  35.  
  36. End Sub
  37.  
  38. Private Sub Timer1_Timer()
  39.  
  40. If SecLeft = 0 Then
  41. SecLeft = 60
  42. MinLeft = MinLeft - 1
  43. If MinLeft = 0 Then Timer1.Enabled = False
  44. End If
  45. SecLeft = SecLeft - 1
  46.  
  47. Text1.Text = MinLeft & " : " & SecLeft
  48.  
  49. End Sub
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Setting Timer/Clock Precision

 
0
  #7
Jul 28th, 2005
Nice Job Visal!!!!
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 5
Reputation: tony mcquaid is an unknown quantity at this point 
Solved Threads: 0
tony mcquaid tony mcquaid is offline Offline
Newbie Poster

Re: Setting Timer/Clock Precision

 
0
  #8
Aug 1st, 2005
Hey!

Ahh, thanks for you help but it seems to be freezing at the 1 minute mark, it's breaking the double digit seconds format (ex: 1:8 instead of 1:08), and its not turning red, or counting back up after it hits zero.

I'm totally lost guys

Any help/tinkering would be greatly appreciated coma. Sorry for being a bother.

Take care,
-Tony
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: Setting Timer/Clock Precision

 
0
  #9
Aug 5th, 2005
try this one

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Dim SecLeft As Integer
  4. Dim MinLeft As Integer
  5.  
  6. Private Sub cmdBreak_Click()
  7. cmdbreak.Enabled = False ' To stop them resetting !
  8. cmdImBack.Enabled = True
  9.  
  10. MinLeft = 15
  11. SecLeft = 0
  12.  
  13. Timer1.Enabled = True
  14. Timer1_Timer ' to draw it once!
  15.  
  16. End Sub
  17.  
  18. Private Sub cmdImBack_Click()
  19.  
  20. cmdImBack.Enabled = False
  21. Timer1.Enabled = False
  22. cmdbreak.Enabled = True
  23. Text1.Text = "--"
  24.  
  25. End Sub
  26.  
  27. Private Sub Form_Load()
  28.  
  29. Timer1.Enabled = False
  30. Timer1.Interval = 1000
  31.  
  32. cmdbreak.Enabled = True
  33. cmdImBack.Enabled = False
  34. Text1.Text = "--"
  35.  
  36. End Sub
  37.  
  38. Private Sub Timer1_Timer()
  39.  
  40. If SecLeft = 0 Then
  41. SecLeft = 60
  42.  
  43. If MinLeft = 0 Then
  44. Timer1.Enabled = False
  45. Exit Sub
  46. End If
  47.  
  48. MinLeft = MinLeft - 1
  49. End If
  50. SecLeft = SecLeft - 1
  51.  
  52. Text1.Text = MinLeft & " : " & Right("0" & SecLeft, 2)
  53.  
  54. End Sub
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 5
Reputation: tony mcquaid is an unknown quantity at this point 
Solved Threads: 0
tony mcquaid tony mcquaid is offline Offline
Newbie Poster

Re: Setting Timer/Clock Precision

 
0
  #10
Aug 10th, 2005
Thanks a lot Invisal!

That count down works well.

One more question though (sorry to be a pain )

How do I make it so it start to count back up after it hits zero, in red text?

Thanks,
-Tony
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC