In a lot different programs I wrote countdown timers, in the end it became very boring and frustrating. I decided to make a countdown timer class. And so I did. I will upload it here so everyone who wants to use, will be able to use it.
The class is made in a "professional way" and includes this:
- Set the time with:
- Timespan
- Seconds
- Minutes
- Hours
- Days
- Add extra time with:
- Timespan
- Seconds
- Minutes
- Hours
- Days
- Start
- Pause
- Reset
- Get the time left in:
- Seconds
- Minutes
- Hours
- Days
- Return the number of:
- Seconds
- Minutes
- Hours
- Days
- Event Each Second.
- Event on times up.
It is possible it will contains some bugs, let me know if you find any.
Do you want to make your own class? Look here to see how.
The class you'll find at the bottom.
/Vswe
UPDATED:
- Removed the ability to use milliseconds, this is for avoiding lagging and delays when the event is raised once a millisecond(bad mistake of me), now the smallest value is seconds.
- small Event bug fix
Last edited by Vswe; 07-23-2009 at 02:24 AM.
Very cool! I almost posted the code on ASCIIBin so people wouldn't have to download.
Thanks for sharing and nice job linking back to your tutorial.
I thought it were better to put it in a .txt file rather then post it inside the code tags since it were pretty long. I'm Glad you liked it![]()
excellent program!!
how to i use it as a class in VB? How to turn a .txt file into a class?
oh ready know, open a VB project then add new item-> select class. -> delete text in class then,
Copy n paste the text from the .txt file into the class.
Rename the class to CountDown.vb
Last edited by WingedPanther; 08-13-2009 at 02:15 PM. Reason: Double post
Love it!
I think the best things in life were invented out of boredom as opposed to necessity. Love it!
Hi, i kinda new in vb, i try to make it work but i can't get the timer running, may be i don't really understand the class much.
can you provide some explanation how the class work. thanks
if you need more help, just tell me.
Code:Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Declares a variable for our countdown timer. Dim Count As CountDown 'Set the time to 3 minutes, this can be done in two ways '----way 1---- Count = New CountDown(0, 3) '-------- '----way 2---- Count = New CountDown Count.SetTime(0, 3) '-------- 'If we want to add some more time we can do so, here I add 35 seconds. Count.AddTime(35) 'add a handler to the tick event AddHandler Count.Tick, AddressOf Count_Tick 'add a handler to the times up event AddHandler Count.TimesOut, AddressOf Times_up 'starts the timer Count.Start() 'It's also possible to pause and reset the timer. ' Count.Pause() ' Count.Reset() End Sub Private Sub Count_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) 'since we added the handler, this code will occur once each second 'get the time left Me.Text = sender.Days & " days, " & sender.Hours & " hours, " & sender.Minutes & " minutes and " & sender.Seconds & " seconds left." 'it's alo possible to use Totalseconds, totalminutes etc. 'This will return the total amount of them. 'For example if we got the time 1 minute and 30 seconds 'TotalSeconds will return 90 and Totalminutes will return 1.5. End Sub Private Sub Times_up(ByVal sender As System.Object, ByVal e As System.EventArgs) 'when the time us up this will happen MessageBox.Show("Wake up!!!") End Sub
There are currently 2 users browsing this thread. (0 members and 2 guests)
Bookmarks