I want to set timer to count down from 40 mins, then messageBox("Time is up"). How do I do this? Thank you.

<FAKE SIGNATURE>

Recommended Answers

All 4 Replies

Simple way would be to set a timer controls interval property to 60000 milliseconds (1 minute), use a variable to either increment from zero to forty or decrement from forty to zero and when condition is reached, msgbox time.

Good Luck

Let me give you a simple exemplar:

'Timer's interval should be set to 1000 for per second calculations...
'XCounter is a variable of long or integer type, depending on how big is your countdown starting number...


Private Sub Timer2_Timer() 'this is a TIMER object...
MSG = OldCaption & " - " & Time 'a caption for your form (optional); MSG & Caption are string variables...
If (MSG <> Caption) And (XCounter > 0) Then
Caption = MSG
XCounter = XCounter - 1
txtRemSecs.Caption = Trim$(Str$(XCounter)) 'preset as a textbox or a caption object...
End If
If XCounter <= 0 Then
'put your "Time's Up!" routines after this line...
'your command
'your command
'your command
'etc. ...
Unload Me
End If
End Sub


'Tailor this code according to your needs and taste...
'Good luck!

aka_amboy,

Your code is not simplier as it will take up more resources because it fires every second. Mine, while based upon the same principle only fires once a minute. Now, your solution may be the correct one if the user wants to view the count down but unfortunatly you have not done the calculation to show the minutes and seconds correctly, you only show a total of 2400 seconds being incremented/decremented.

Good Luck

Indeed, I'm thinking of a countdown timer that is displayed. And my code was NOT intended to display a digital timer (i.e., 00:00:10, 00:00:09, 00:00:08, and so on...) but ONLY a plain number display that counts down.

That's why I advised our friend to tailor my example according to his taste and needs.

If I haven't helped him, perhaps, I assume I have given him the opportunity to think and expand to other alternatives. It's not good for newbie programmers to be spoon-fed with codes; let's not encourage laziness...

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.