944,198 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Jul 21st, 2005
0

Setting Timer/Clock Precision

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tony mcquaid is offline Offline
5 posts
since Jul 2005
Jul 22nd, 2005
0

Re: Setting Timer/Clock Precision

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jul 24th, 2005
0

Re: Setting Timer/Clock Precision

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tony mcquaid is offline Offline
5 posts
since Jul 2005
Jul 26th, 2005
0

Re: Setting Timer/Clock Precision

I'm sorry, I never recieved the e-mail. If you could post it here as a .zip attachment, that would be great.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Jul 27th, 2005
0

Re: Setting Timer/Clock Precision

Here you go

Thanks a million,
-Tony
Attached Files
File Type: zip tonyproject.zip (6.7 KB, 38 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tony mcquaid is offline Offline
5 posts
since Jul 2005
Jul 28th, 2005
0

Re: Setting Timer/Clock Precision

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
Reputation Points: 350
Solved Threads: 63
Posting Pro
invisal is offline Offline
562 posts
since Mar 2005
Jul 28th, 2005
0

Re: Setting Timer/Clock Precision

Nice Job Visal!!!!
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Aug 1st, 2005
0

Re: Setting Timer/Clock Precision

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tony mcquaid is offline Offline
5 posts
since Jul 2005
Aug 5th, 2005
0

Re: Setting Timer/Clock Precision

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
Reputation Points: 350
Solved Threads: 63
Posting Pro
invisal is offline Offline
562 posts
since Mar 2005
Aug 10th, 2005
0

Re: Setting Timer/Clock Precision

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tony mcquaid is offline Offline
5 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: sql query updating problem
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Problem formating VB string for clipboard





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC