Results 1 to 21 of 21

Thread: [RESOLVED] I'm trying to set an alarm clock with more than one alarm

  1. #1

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Resolved [RESOLVED] I'm trying to set an alarm clock with more than one alarm

    I'm using a class Alarm:
    VB Code:
    1. Public Class Alarm
    2.     Public message As String
    3.     Public alarmTime As Date
    4.     Public fileToPlay As String
    5.     Public play, showMessageBox, showPopupMessage As CheckState
    6.  
    7.     Public timer As Timer
    8. 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.
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    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.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    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.
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  4. #4

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    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...
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  5. #5
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    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.

  6. #6
    Member
    Join Date
    Jan 2006
    Location
    Manchester UK
    Posts
    55

    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

  7. #7

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Re: I'm trying to set an alarm clock with more than one alarm

    Quote 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.
    Quote 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.
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  8. #8
    Addicted Member justinc911's Avatar
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    233

    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

  9. #9
    Addicted Member justinc911's Avatar
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    233

    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

  10. #10

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Re: I'm trying to set an alarm clock with more than one alarm

    Quote 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?
    Quote 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.
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  11. #11
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    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
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  12. #12
    Addicted Member justinc911's Avatar
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    233

    Re: I'm trying to set an alarm clock with more than one alarm

    definitly with threads

    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

  13. #13

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Re: I'm trying to set an alarm clock with more than one alarm

    Quote 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.
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  14. #14
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    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.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  15. #15
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    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.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  16. #16
    Fanatic Member
    Join Date
    May 2005
    Posts
    608

    Re: I'm trying to set an alarm clock with more than one alarm

    Quote 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:
    1. Public Sub launchAlarm()
    2.     Dim myTimer As New System.Timers.Timer(1000)
    3.     myTimer.Enabled = True
    4.     myTimer.Start
    5. 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:
    1. Dim myThread As Thread = New Thread(AddressOf launchAlarm)
    2.     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.

  17. #17
    Hyperactive Member
    Join Date
    Jul 2004
    Location
    Kansas, USA
    Posts
    352

    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."

  18. #18

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Re: I'm trying to set an alarm clock with more than one alarm

    Quote 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:
    Quote 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.
    Quote 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.
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  19. #19

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    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?
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  20. #20
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: I'm trying to set an alarm clock with more than one alarm

    Check this out to get the differences in timers
    http://msdn.microsoft.com/msdnmag/is...T/default.aspx
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  21. #21

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Thank you

    Thank you all for your help. Problem solved.
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width