|
-
Mar 3rd, 2013, 12:30 PM
#1
Thread Starter
Hyperactive Member
Req: Countdown Timer - Easiest way please
Can someone point me in the right direction of a countdown timer. I've used the search and most of the code refers to clocks with start and stop buttons. I just want to add a simple timer ticking down, no buttons needed to reset or anything.
**Okay thanks to MetalInquisitor, I have a counter ticking down, but what if I want the ticker to be real and live, so if I close the application the ticker is still counting down, is this possible?
Thank you.
Last edited by jokerfool; Mar 3rd, 2013 at 03:33 PM.
-
Mar 3rd, 2013, 12:57 PM
#2
Addicted Member
Re: Req: Countdown Timer - Easiest way please
Try something like this (I've never used a Timer before, so there might be much more efficient ways to do this)
I added a Timer and a Label (for displaying countdown) on the Form. Timer starts at 100 and decreases by 1 each passing second (In the Timer Tick event). I set Timer interval at 1000 millisecond which equals to 1 second:
vb.net Code:
Public Class Form1
Dim counter As Integer = 100
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 1000
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
counter -= 1
Label1.Text = counter.ToString
End Sub
End Class
Last edited by MetalInquisitor; Mar 3rd, 2013 at 03:01 PM.
-
Mar 3rd, 2013, 01:08 PM
#3
Re: Req: Countdown Timer - Easiest way please
Yup like that except I'd probably use a numerical up/down so that you could do the arithmetic directly.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Mar 3rd, 2013, 01:35 PM
#4
Junior Member
Re: Req: Countdown Timer - Easiest way please
Add a timer. On the timer options enable = true.
Double click timer.
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text -= 1
End Sub
-
Mar 3rd, 2013, 03:23 PM
#5
Thread Starter
Hyperactive Member
Re: Req: Countdown Timer - Easiest way please
-
Mar 3rd, 2013, 03:29 PM
#6
Thread Starter
Hyperactive Member
Re: Req: Countdown Timer - Easiest way please
Okay that worked nicely MetalInquisitor, thank you. Now for the question. If I wanted the timer set for e.g. lets say 6 hrs, but I wanted it live, so if I close it after 30mins and reopen its still ticking down and hasnt restarted, is this possible?
-
Mar 3rd, 2013, 04:58 PM
#7
Re: Req: Countdown Timer - Easiest way please
What do you mean by "close it after 30mins"? Close what? the timer or the app?
-
Mar 3rd, 2013, 05:52 PM
#8
Re: Req: Countdown Timer - Easiest way please
You can make it do exactly what you stated, but what you can't do is have an app that keeps counting down and will take some action if it is closed. Therefore, you HAVE to have the app running for the action to take place. It might be hidden, but it MUST be running. If you know that it will be running, then you can keep the timer going, though with a bit of difficulty (because the timer wouldn't actually be running, you'd be faking it). What you would do would be to save the amount of time on the timer AND the current system time, into two different project Settings. When the app starts, it checks those settings. If the settings are there, it subtracts the saved time from the current system time to determine how much time has elapsed since the app closed. You would then subtract that elapsed time from the countdown that was saved in the other setting, and if there is time left, you'd start counting down from there.
My usual boring signature: Nothing
 
-
Mar 3rd, 2013, 06:33 PM
#9
Re: Req: Countdown Timer - Easiest way please
Seems a bit long winded. Why not just add the countdown period to Now to get a target time and save that to Settings?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Mar 3rd, 2013, 06:58 PM
#10
Re: Req: Countdown Timer - Easiest way please
Yeah, that would work, too, with the same caveats about the program needing to be running. You are saving the same thing either way, my way just used an extra setting for no good reason.
My usual boring signature: Nothing
 
-
Mar 4th, 2013, 02:10 AM
#11
Thread Starter
Hyperactive Member
Re: Req: Countdown Timer - Easiest way please
Okay rephrasing question. I wanted to have a Live Countdown timer, so I understand that some other variables may come into it like running from a domain or something, so if it ticks down from 12 hrs and it gets too 11hrs and 32mins and the user closes the app then reopens the app it might now say 9 hrs 13 mins.
So the live information would have to come from somewhere else and displayed through the software.
Possible?
-
Mar 4th, 2013, 02:36 AM
#12
Re: Req: Countdown Timer - Easiest way please
I'm curious....have you considered that the user could switch off the computer ? I mean is that important ?
-
Mar 4th, 2013, 03:37 AM
#13
Fanatic Member
Re: Req: Countdown Timer - Easiest way please
your going to have to have something running in the background.
look into minimizing your form into the system tray, that way its hidden, then create a menu for the tray icon that you can use to set up the timer
use a 2nd form for the settings only, dont add a timer control to it.
that way you can unload that particular form from memory when not in use.
and then you can use other icon properties to display a time or hide and show the main form which you can design to show the time.
system tray icon is simple to do (was in vb6 so .net should be easier)
save the starting time to a file and use that to determine the current time left using the time() function or something in case its turned off.
Last edited by GBeats; Mar 4th, 2013 at 03:40 AM.
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work

-
Mar 4th, 2013, 03:42 AM
#14
-
Mar 4th, 2013, 11:09 AM
#15
Re: Req: Countdown Timer - Easiest way please
What dunfiddlin and I suggested would behave exactly the way you describe without having some kind of external source, or anything running in the background. The key question is whether or not the count reaching 0 should do anything when the app is not open. If the count reaching 0 should do something at all times, then the app would have to be running, which also means that the computer would have to be running. If you don't care about that, then what we were suggesting is that when the app shuts down, you stop the countdown (it will stop anyways because the app is no longer running), but you store enough information that you can re-start the countdown correctly when the app re-starts. Then, when you start up the app, it checks that stored information, figures out how much time has elapsed since the shutdown, and resumes the countdown at the point it would have reached had you not shut down the app.
My usual boring signature: Nothing
 
-
Mar 4th, 2013, 11:21 AM
#16
Fanatic Member
Re: Req: Countdown Timer - Easiest way please
i only added because nobody really made it clear that you need it to run if you want some sort of response, and hiding it in sys tray is a perfect place to keep it out of the way.
but yea the question was lacking a few details.
lol always the case, someone mind is runing away with thoughts and of course they know exactly what they want and sometimes its hard to voice it out , hopefully mr jokerfool will have enough info to carry on
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|