|
-
Feb 27th, 2006, 05:27 PM
#1
Thread Starter
Addicted Member
[RESOLVED] I'm trying to set an alarm clock with more than one alarm
I'm using a class Alarm:
VB Code:
Public Class Alarm
Public message As String
Public alarmTime As Date
Public fileToPlay As String
Public play, showMessageBox, showPopupMessage As CheckState
Public timer As Timer
End Class
and I have a list of Alarm objects. I want to be able to set a list of alarms, not just one. The problem is I need a Timer_Tick() method for each of them, and I don't know how to implement this.
Any suggestions? Thank you.
-
Feb 27th, 2006, 06:16 PM
#2
Re: I'm trying to set an alarm clock with more than one alarm
Might be easier to inherit the Timer class then implimenting your own Tick event.
-
Feb 27th, 2006, 06:22 PM
#3
Thread Starter
Addicted Member
Some code...?
Could you post some code please? Only a few lines I think would be enough for me to figure out what I have to do... I'm quite a newbie to VB. Thank you.
-
Mar 3rd, 2006, 12:02 PM
#4
Thread Starter
Addicted Member
Could you give me a hint, please?
Oka, I did this... I have a class Alarm which inherits System.Windows.Forms.Timer and in this class I have the method Alarm_Tick implemented. When I click a button on the form I start the timer and set it's Interval property to a value. Can you tell me where am I wrong? Because it doesn't work and I can't figure out why...
-
Mar 3rd, 2006, 12:26 PM
#5
Re: I'm trying to set an alarm clock with more than one alarm
Create a thread for each alarm? Inside each thread, create it's own timer.
HTH
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
-
Mar 3rd, 2006, 12:26 PM
#6
Member
Re: I'm trying to set an alarm clock with more than one alarm
do you have to enable it? when you drag a timer from the toolbox its not enabled as default
-
Mar 3rd, 2006, 02:58 PM
#7
Thread Starter
Addicted Member
Re: I'm trying to set an alarm clock with more than one alarm
 Originally Posted by big blue alien
do you have to enable it? when you drag a timer from the toolbox its not enabled as default
Yes, I enable it.
 Originally Posted by HoraShadow
Create a thread for each alarm? Inside each thread, create it's own timer.
HTH
HoraShadow
How do you do this? Can you give me an example please?
Thank you.
-
Mar 3rd, 2006, 03:14 PM
#8
Addicted Member
Re: I'm trying to set an alarm clock with more than one alarm
So let me get this striaght you are making an alarm clock that doesn't go off based on time? Cause otherwise why don't you just use a date and time pickers to set the alarm off, would not that be easier? Or am I way off base, I am usally good in helping newer members since I am fairly new myself to vb.
Using Visual Studio 2003 Professional Edition of Visual Basic .Net 2003 with .Net Framework 1.1
VB Website
When Nature has work to be done, she creates a genius to do it.
"You are a great champion, when you ran the ground shook, the water rumbled and the sky opened, and mere mortals parted, parted the way to victory, where you'll meet me on the podium, where the gold will be glistening around my neck."
What lies behind us and what lies before us are small matters compared to what lies within us.
-Ralph Waldo Emerson
-
Mar 3rd, 2006, 03:17 PM
#9
Addicted Member
Re: I'm trying to set an alarm clock with more than one alarm
you should post the complete code so people can test it well they are fixing it. If you don't mind! thanks
Using Visual Studio 2003 Professional Edition of Visual Basic .Net 2003 with .Net Framework 1.1
VB Website
When Nature has work to be done, she creates a genius to do it.
"You are a great champion, when you ran the ground shook, the water rumbled and the sky opened, and mere mortals parted, parted the way to victory, where you'll meet me on the podium, where the gold will be glistening around my neck."
What lies behind us and what lies before us are small matters compared to what lies within us.
-Ralph Waldo Emerson
-
Mar 3rd, 2006, 03:24 PM
#10
Thread Starter
Addicted Member
Re: I'm trying to set an alarm clock with more than one alarm
 Originally Posted by justinc911
So let me get this striaght you are making an alarm clock that doesn't go off based on time? Cause otherwise why don't you just use a date and time pickers to set the alarm off, would not that be easier? Or am I way off base, I am usally good in helping newer members since I am fairly new myself to vb.
I'm trying to make an alarm clock which can set more than one alarm. I pick the date and time from a DateTimePicker and when I click a button, I want to set an alarm. After this, I want to be able to set another alarm by choosing another date and time from the DateTimePicker and click the button... and so on...
Probably I need to do this with threads, or at least I can't find another solution to this.
Do you have any other suggestions?
 Originally Posted by justinc911
you should post the complete code so people can test it well they are fixing it. If you don't mind! thanks
I can post the code, but I think it wouldn't help you at all, because I'm trying to find out right now how to do this, and that's why I did't do almost anything until now.
-
Mar 3rd, 2006, 03:37 PM
#11
Frenzied Member
Re: I'm trying to set an alarm clock with more than one alarm
Here is what you should probably do:
Use the Alarm class that you have.
Create an AlarmCollection class. This will store a list of alarms similar to how an array stores objects.
Here are a few links about collections
http://www.informit.com/articles/art...?p=101592&rl=1
http://msdn.microsoft.com/library/de...ml/vb04c10.asp
-
Mar 3rd, 2006, 03:58 PM
#12
Addicted Member
Re: I'm trying to set an alarm clock with more than one alarm
Using Visual Studio 2003 Professional Edition of Visual Basic .Net 2003 with .Net Framework 1.1
VB Website
When Nature has work to be done, she creates a genius to do it.
"You are a great champion, when you ran the ground shook, the water rumbled and the sky opened, and mere mortals parted, parted the way to victory, where you'll meet me on the podium, where the gold will be glistening around my neck."
What lies behind us and what lies before us are small matters compared to what lies within us.
-Ralph Waldo Emerson
-
Mar 3rd, 2006, 04:00 PM
#13
Thread Starter
Addicted Member
Re: I'm trying to set an alarm clock with more than one alarm
 Originally Posted by justinc911
definitly with threads
Then I'll do so... I just began reading an example from 101 VB.NET Samples... Thank you.
-
Mar 3rd, 2006, 04:01 PM
#14
Frenzied Member
Re: I'm trying to set an alarm clock with more than one alarm
Threads doesn't do anything in answering the question. The question is how to have multiple alarms. How would you store multiple alarms with threads? You need a way to keep track of all the alarms. That is what the collection class is for.
-
Mar 3rd, 2006, 04:09 PM
#15
Re: I'm trying to set an alarm clock with more than one alarm
I would just create a seperate alarm class that inherits the Timer. Then have an array of times for the alarms within the class.
Then, on each Tick it'll check if it's time to go off or not for all the alarms.
Very simple.
If you want something with better performance, you could make it so it only checks certain ones every hour until it's close to going off then set it to check every minute and/or second.
-
Mar 3rd, 2006, 04:51 PM
#16
Re: I'm trying to set an alarm clock with more than one alarm
 Originally Posted by mpdeglau
Threads doesn't do anything in answering the question. The question is how to have multiple alarms. How would you store multiple alarms with threads? You need a way to keep track of all the alarms. That is what the collection class is for.
Yes, for that part either collections or some kind of db.
But the part I'm aiming for, is how to launch all the alarms, because they were talking about inheriting the timer, and doing it in a very complicated way that needs a HUGE logic structure to check every milisecond if it's time to launch one of the alarms.
So, here it goes... how I would do it with threads:
You create an alarm class that accepts a time in miliseconds in which the has to go off as a parameter. Property will do, or even an overloaded constructor, that's up to you.
That will be the multi threated class.
Then inside that class, you dimension the Timer
VB Code:
Public Sub launchAlarm()
Dim myTimer As New System.Timers.Timer(1000)
myTimer.Enabled = True
myTimer.Start
End Sub
(That example above is every second, you have to put the right time it has to set it off).
And then each time you add an alarm, you just thread the class with the right time and voila, you got yourself a multi threading timer in very few steps.
This is how you launch your thread:
VB Code:
Dim myThread As Thread = New Thread(AddressOf launchAlarm)
myThread.Start()
HTH
HoraShadow
Last edited by HoraShadow; Mar 3rd, 2006 at 05:08 PM.
I do like the reward system. If you find that my post was useful, rate it.
-
Mar 3rd, 2006, 05:53 PM
#17
Hyperactive Member
Re: I'm trying to set an alarm clock with more than one alarm
I suppose that it's all a matter of how many alarms and how long the alarms need to run for.
What I would do is use a collection and add each alarm as a seperate item in the collection. Set a single timer up. In the timer tick event use a loop to examine the array or collection to see if the time for any item has passed. If it has then sound an alarm and dispose of that particular item in the collection. If you wanted to you could create a class for the alarm item that would keep all the data for any single alarm.
This solution stores the multiple alarm objects in a single collection so that you can iterate through them. I see no reason that you need seperate threads for each alarm unless you need more exact timing of small units of time.
If you are keeping track of "it's time to go to this or that meeting" than every second is plenty. Also, there will be a limit to how many threads your computer can deal with without slowing down and getting sluggish. I have seen some posts in this forum that indicate 10 or so. I don't know much about that but you could search.
Thanks,
Eric
--------------------------------------------------------------------------------------------------------------------
VB.net/C# ... Visual Studio 2019
"None of us are as smart as all of us."
-
Mar 4th, 2006, 09:03 AM
#18
Thread Starter
Addicted Member
Re: I'm trying to set an alarm clock with more than one alarm
 Originally Posted by kasracer
I would just create a seperate alarm class that inherits the Timer. Then have an array of times for the alarms within the class.
Then, on each Tick it'll check if it's time to go off or not for all the alarms.
Very simple.
If you want something with better performance, you could make it so it only checks certain ones every hour until it's close to going off then set it to check every minute and/or second.
Maybe you're right, but you're not answering my question. In a previous post, I wrote:
 Originally Posted by zahadumy
Oka, I did this... I have a class Alarm which inherits System.Windows.Forms.Timer and in this class I have the method Alarm_Tick implemented. When I click a button on the form I start the timer and set it's Interval property to a value. Can you tell me where am I wrong? Because it doesn't work and I can't figure out why... 
Thank you HoraShadow, I'll try this right now. I hope it will work.
 Originally Posted by flycast
What I would do is use a collection and add each alarm as a seperate item in the collection. Set a single timer up. In the timer tick event use a loop to examine the array or collection to see if the time for any item has passed. If it has then sound an alarm and dispose of that particular item in the collection. If you wanted to you could create a class for the alarm item that would keep all the data for any single alarm.
This solution stores the multiple alarm objects in a single collection so that you can iterate through them. I see no reason that you need seperate threads for each alarm unless you need more exact timing of small units of time.
I already tried this, but I don't know why it doesn't go through the timer tick method implemented... Probably I'm not doing something... Do you have any ideas?
Thank you all for your help.
Last edited by zahadumy; Mar 4th, 2006 at 09:09 AM.
-
Mar 4th, 2006, 09:35 AM
#19
Thread Starter
Addicted Member
Re: I'm trying to set an alarm clock with more than one alarm
What's the difference between System.Windows.Forms.Timer and System.Timers.Timer?
-
Mar 4th, 2006, 11:21 AM
#20
Frenzied Member
Re: I'm trying to set an alarm clock with more than one alarm
-
Mar 4th, 2006, 04:29 PM
#21
Thread Starter
Addicted Member
Thank you
Thank you all for your help. Problem solved.
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
|