Sunday, 18 December 2016

Alarm Clock with Sound Message in VB.NET

Go to File, click New Project, and choose Windows Application. Next, add two Timers named Timer2 for displaying the current time and Timer1 for displaying the time to be alarmed. Insert DateTimePicker named DateTimePicker1 to be used as getting the alarmed time, one TextBox named TextBox1 for inputting a message for the alarm, two Labels named Label1 for displaying if the alarm clock is set and lblCurtime for displaying the current time in this label, and one Button named Button1 for the setup of the time to be alarmed. You must design your interface like this:
In Timer1_Tick control, put this code below.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If TimeOfDay = DateTimePicker1.Text Then

            Dim voice = CreateObject("SAPI.spvoice")


            voice.speak(TextBox1.Text)
            lblStatus.Text = "Alarm is not set!"
        End If
    End Sub

In Timer2_Tick control, put this code below.

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        lblCurtime.Text = TimeOfDay
    End Sub

In our Form1_Load, put this code below.

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer2.Enabled = True
    End Sub
This will display the current time when loading the form.In our Button1_Click for the setup of the alarm, put this code below.

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetAlarm.Click
        Timer1.Enabled = True
        lblStatus.Text = "Alarm is set!"
    End Sub

Timer1 is enabled because we have set the time of the alarmed time to be equal to the current time and will display to the user that time is now set!


0 comments:

Post a Comment