• Welcome to ForumKorner!
    Join today and become a part of the community.

[Tutorial][VB] Alarm Clock

hotspice

Member
Reputation
0
Alarm Clock


AlarmClock.JPG


To make an alarm clock, we need a timer that checks at every tick whether the current time matches with alarm time or not, if both time matches then the clock will generate an alarm tone.
My.Computer.Audio.Play() plays the audio file.
My.Computer.Audio.Stop() stops the audio file.
DateTime.Now.ToLongTimeString gives the current time.

Code

Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
lbl_Time.Text = DateTime.Now.ToLongTimeString
If rbtn_SetAlarm.Checked = True Then
If dtp_Time.Text = DateTime.Now.ToLongTimeString Then
My.Computer.Audio.Play(My.Resources.ringout, AudioPlayMode.BackgroundLoop)
End If
Else
My.Computer.Audio.Stop()
End If
End Sub
 
Top