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

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.

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

I'm sorry, I never recieved the e-mail. If you could post it here as a .zip attachment, that would be great.

Here you go :)

Thanks a million,
-Tony

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.

Option Explicit

Dim SecLeft As Integer
Dim MinLeft As Integer

Private Sub cmdBreak_Click()
cmdbreak.Enabled = False ' To stop them resetting !
cmdImBack.Enabled = True

MinLeft = 15
SecLeft = 0

Timer1.Enabled = True
Timer1_Timer ' to draw it once!

End Sub

Private Sub cmdImBack_Click()

cmdImBack.Enabled = False
Timer1.Enabled = False
cmdbreak.Enabled = True
Text1.Text = "--"

End Sub

Private Sub Form_Load()

Timer1.Enabled = False
Timer1.Interval = 1000

cmdbreak.Enabled = True
cmdImBack.Enabled = False
Text1.Text = "--"

End Sub

Private Sub Timer1_Timer()

If SecLeft = 0 Then
    SecLeft = 60
    MinLeft = MinLeft - 1
    If MinLeft = 0 Then Timer1.Enabled = False
End If
SecLeft = SecLeft - 1

Text1.Text = MinLeft & " : " & SecLeft

End Sub

Nice Job Visal!!!!

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

try this one

Option Explicit

Dim SecLeft As Integer
Dim MinLeft As Integer

Private Sub cmdBreak_Click()
cmdbreak.Enabled = False ' To stop them resetting !
cmdImBack.Enabled = True

MinLeft = 15
SecLeft = 0

Timer1.Enabled = True
Timer1_Timer ' to draw it once!

End Sub

Private Sub cmdImBack_Click()

cmdImBack.Enabled = False
Timer1.Enabled = False
cmdbreak.Enabled = True
Text1.Text = "--"

End Sub

Private Sub Form_Load()

Timer1.Enabled = False
Timer1.Interval = 1000

cmdbreak.Enabled = True
cmdImBack.Enabled = False
Text1.Text = "--"

End Sub

Private Sub Timer1_Timer()

If SecLeft = 0 Then
    SecLeft = 60
    
    If MinLeft = 0 Then
        Timer1.Enabled = False
        Exit Sub
    End If
    
    MinLeft = MinLeft - 1
End If
SecLeft = SecLeft - 1

Text1.Text = MinLeft & " : " & Right("0" & SecLeft, 2)

End Sub

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

Hi

I am attaching a timer project. Look at it. It has three text box where u can enter the time u want the timer to go on. once it touches zero it will count back till the same time u entered.
Hope it helps!!!

Marikanna

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.