Create Alarm Clock in ASP.NET using VB.NET
In this article you learn that how to create a alarm clock.
Introduction
In this article we are discussing that how can you create a alarm clock called timers. Here user can click the Start Clock Button to start the clock which is displayed in a Label control. The clock's display is updated once a second in the Timer in this example because we have set the timer control's interval property to 1000 milliseconds or one seconds, which means its tick event occurs every seconds. We update the Labels Text's like this in the Tick event handler
The user can also enter a time for the alarm to go off in three Textboxes in 24 hours format and click the Alarm on RadioButton. When the Current Time Equal or exceeds the alarm time, the clock will beep once a second until a user clicks the Alarm Off RadioButton.
Here we are using handy properties as TimeOfDay, which returns a Date Time object holding the current time of day. which returns a Date Time Holding today's date and now. Which returns a Date Time object that holds both Today's Time and date.
Getting Started
- Simply create a new ASP.NET web application.
- Drag two RadioButton ,a Label, three Textbox and a Button control on your web page. The page will look like below.

- you can also add controls by the below code.
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"/>
<asp:RadioButton ID="RadioButton1" runat="server" Text="Alarm On" />
<asp:RadioButton ID="RadioButton2" runat="server" Text="Alarm Off" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Set Alarm"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Width="43px"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" Width="43px"></asp:TextBox>
<asp:TextBox ID="TextBox3" runat="server" Width="43px"></asp:TextBox>
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="2000">
</asp:Timer>
<asp:Button ID="Button1" runat="server" Text="Start Clock" />
<br />
<br />
<br />
</asp:Content>
- Then attach the below code in code behind file of the web page.
Dim blnAlarm As Boolean = False
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = TimeOfDay
If TextBox1.Text <> "" And TextBox2.Text <> "" And _
TextBox3.Text <> "" Then
Dim AlarmTime = New DateTime(Today.Year, Today.Month, _
Today.Day, CInt(TextBox1.Text), CInt(TextBox2.Text), _
CInt(TextBox3.Text))
If Now > AlarmTime And blnAlarm Then
Beep()
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles RadioButton1.CheckedChanged
If RadioButton1.Checked Then
blnAlarm = True
End If
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles RadioButton2.CheckedChanged
If RadioButton1.Checked Then
blnAlarm = False
End If
End Sub
- Now run your application.
Output




Summary
In this article you learned that how to create a Alarm Clock.