Saturday, 28 January 2012

How to make your own digital clock in vb.net?


How to make your own digital clock in vb.net?
In this tutorial you can make digital clock with use of timer
Step1:
Open Microsoft visual studio
Step2:
Open file new àwindows form application à rename it as my own clock
Step3:
Drag and drop the three textbox, four labels, one timer
Step4:
Write or copy the below code
Code:
Public Class Form1
    Private SubTimer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesTimer1.Tick
        TextBox3.Text = TextBox3.Text + 1
        If TextBox3.Text = "60"Then
            TextBox3.Text = "00"
            TextBox2.Text = TextBox2.Text + 1
            If TextBox2.Text = "60"Then
                TextBox2.Text = "00"
                TextBox1.Text = TextBox1.Text + 1
                If TextBox1.Text = "13" Then
                    TextBox1.Text = "01"
                End If
            End If
        End If
    End Sub
    Private SubForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
        Timer1.Start()
        TextBox1.Text = Now.Hour
        TextBox2.Text = Now.Minute
        TextBox3.Text = Now.Second
        If TextBox1.Text >= "00"Then
            Label4.Text = "AM"
        ElseIf TextBox1.Text <= "12"Then
            Label4.Text = "PM"
        End If
    End Sub
End Class

Output: