VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



alarm clock

by Navneet Sahota (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 30th October 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

alarm clock

API Declarations


Dim AlarmTime
Const conMinimized = 1


Rate alarm clock




Private Sub Form_Click()
    AlarmTime = InputBox("Enter alarm time", "VB Alarm", AlarmTime)
    If AlarmTime = "" Then Exit Sub
    If Not IsDate(AlarmTime) Then
        MsgBox "The time you entered was not valid."
    Else                                    ' String returned from InputBox is a valid time,
        AlarmTime = CDate(AlarmTime)        ' so store it as a date/time value in AlarmTime.
    End If
End Sub

Private Sub Form_Load()
    AlarmTime = ""
End Sub

Private Sub Form_Resize()
    If WindowState = conMinimized Then      ' If form is minimized, display the time in a caption.
        SetCaptionTime
    Else
        Caption = "Alarm Clock"
    End If
End Sub

Private Sub SetCaptionTime()
    Caption = Format(Time, "Medium Time")   ' Display time using medium time format.
End Sub

Private Sub lblTime_Click()

End Sub

Private Sub Timer1_Timer()
Static AlarmSounded As Integer
    If lblTime.Caption <> CStr(Time) Then
        ' It's now a different second than the one displayed.
        If Time >= AlarmTime And Not AlarmSounded Then
            Beep
            MsgBox "Alarm at " & Time
            AlarmSounded = True
        ElseIf Time < AlarmTime Then
            AlarmSounded = False
        End If
        If WindowState = conMinimized Then
            ' If minimized, then update the form's Caption every minute.
            If Minute(CDate(Caption)) <> Minute(Time) Then SetCaptionTime
        Else
            ' Otherwise, update the label Caption in the form every second.
            lblTime.Caption = Time
        End If
    End If
End Sub



Download this snippet    Add to My Saved Code

alarm clock Comments

No comments have been posted about alarm clock. Why not be the first to post a comment about alarm clock.

Post your comment

Subject:
Message:
0/1000 characters