Results 1 to 8 of 8

Thread: [RESOLVED] Alarm

  1. #1

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Resolved [RESOLVED] Alarm

    What is a real efficient way of doing making an alarm, i need the current time shown in a label, the alarm time in another and the countdown in another. I am setting and getting the alarm time alright. But this countdown part and then the actual alarm is a little tricky.

    As for format, doesn't matter at the moment, but the current time is just...
    Code:
     lblTime = Time
    then the format for the alarm time at the moment is "hh:mmAM" So the input would be "8:45AM or 845:PM" now i just sort of need the countdown time. Any ideas?
    Last edited by Paul M; Feb 9th, 2008 at 04:43 AM.

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Alarm

    How about something like this?
    Code:
    Private daAlarmTime As Date
    Private daCountDown As Date
    Private daNow As Date
    
    Private Sub cmdStartCountDown_Click()
    Timer1.Enabled = True
    daAlarmTime.Caption = CDate(labAlarmTime.Caption)
    End Sub
    
    Private Sub Form_Load()
    Timer1.Enabled = False
    Timer1.Interval = 1000
    labCurrentTime.Caption = Format(Now, "hh:mm:ss")
    daAlarmTime = CDate(InputBox("Enter Alarm Time"))
    labAlarmTime.Caption = Format(daAlarmTime, "hh:mm:ss")
    End Sub
    
    Private Sub Timer1_Timer()
    Dim daDiff As Date
    labCurrentTime.Caption = Format(Now, "hh:mm:ss")
    daNow = CDate(labCurrentTime.Caption)
    daDiff = daAlarmTime - daNow
    labTimeToGo.Caption = Format(daDiff, "hh:mm:ss")
    If daNow >= daAlarmTime Then
        MsgBox "ALARM"
        Timer1.Enabled = False
    End If
    End Sub
    Last edited by Doogle; Feb 9th, 2008 at 05:10 AM. Reason: Missed a couple of .Caption's

  3. #3

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Alarm

    Nah that doesn't do it correctly.

  4. #4
    Junior Member
    Join Date
    Feb 2008
    Posts
    21

    Re: Alarm

    HI, Wish i had a bit more time to right this but just kind of chucked it together, if you ahve a timer on your form, set the timer to 1000 interval and use something like this
    vb Code:
    1. '//Top of the Code Section
    2. Private AlarmTime As Date
    3.  
    4. Private Sub Form_Load()
    5.     lblTime = Time
    6.      
    7.     '//Set Alarm TIme To 8pm but in 24 hour
    8.     '//When you update your Alarm Time Label, you can
    9.     '//Change the format of the time to display how you want    
    10.     AlarmTIme = "20:00"
    11.  
    12. End Sub
    13.  
    14. Private Sub Timer1_Timer()
    15.     '//Update The Label
    16.     lblTime = Time
    17.  
    18.     '//Works it out in 24 hour format then you dont need to check _
    19.     '//To see if it is AM or PM
    20.     If Format(Time, "hh:mm") = Format(AlarmTime, "hh:mm") Then
    21.         '//Alarm Code Here
    22.         MsgBox "alarm"
    23.         '//Stop The Timer to stop duplicate alarms running
    24.         '//Every Second
    25.         Timer1.Enabled = False: Exit Sub
    26.     End If
    27. End Sub

  5. #5
    Junior Member
    Join Date
    Feb 2008
    Posts
    21

    Re: Alarm

    Here is what i wrote, so i could show you the code
    thought it might jus be as easy to upload the example
    so that you can see, ive added a little checks here and there aswell

    Kind Regards
    Devon
    Attached Files Attached Files

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Alarm

    Quote Originally Posted by Paul M
    Nah that doesn't do it correctly.
    Strange, in what way doesn't it do it correctly ?

  7. #7

    Thread Starter
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Alarm

    Your's just plainly didn't work correctly, it was a little messy too

    I tidied devon's up a little and it seems to be working flawlessly

  8. #8
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [RESOLVED] Alarm

    Well, it displayed the current time (labCurrentTime), the alarm time (labAlarmTime) and displayed a count down, second by second (labTimeToGo). I obviously didn't understand you question. Sorry.

    I'm not sure about "messy" though

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