ad

Make a Simple clock using visual basic 2008

Download Source code

Codes For Showing the error messages when the combobox are left empty

        If chandbox.SelectedItem = "" Then
            MessageBox.Show("Please select the color of hand")
            chandbox.Focus()
        ElseIf whandbox.SelectedItem = "" Then
            MessageBox.Show("Please select the correct width of the hand")
            whandbox.Focus()
        ElseIf cclockbox.SelectedItem = "" Then
            MessageBox.Show("Please select the color of square clockface")
            cclockbox.Focus()
        ElseIf chandbox.SelectedItem = cclockbox.SelectedItem Then
            MessageBox.Show("The color of hand and color of square face cannot be the same")
        ElseIf sepbox.SelectedItem = "" Then
            MessageBox.Show("Please select The Seperation Between Consecutive Positions Of The Hand :")
            sepbox.Focus()
        ElseIf speedbox.SelectedItem = "" Then
            MessageBox.Show("Please select the speed of rotation")
            speedbox.Focus()
        ElseIf dirbox.SelectedItem = "" Then
            MessageBox.Show("Please select the direction of rotation")
            dirbox.Focus()
        Else        
  
Code for chosing the color of the hand
            If chandbox.SelectedItem = "aliceblue" Then
                c.Color = Drawing.Color.AliceBlue
            ElseIf chandbox.SelectedItem = "black" Then
                c.Color = Drawing.Color.Black
            ElseIf chandbox.SelectedItem = "blue" Then
                c.Color = Drawing.Color.Blue
            ElseIf chandbox.SelectedItem = "chocolate" Then
                c.Color = Drawing.Color.Chocolate
            ElseIf chandbox.SelectedItem = "crimson" Then
                c.Color = Drawing.Color.Crimson
            ElseIf chandbox.SelectedItem = "gold" Then
                c.Color = Drawing.Color.Gold
            ElseIf chandbox.SelectedItem = "green" Then
                c.Color = Drawing.Color.Green
            ElseIf chandbox.SelectedItem = "maroon" Then
                c.Color = Drawing.Color.Maroon
            ElseIf chandbox.SelectedItem = "orange" Then
                c.Color = Drawing.Color.Orange
            ElseIf chandbox.SelectedItem = "pink" Then
                c.Color = Drawing.Color.Pink
            ElseIf chandbox.SelectedItem = "red" Then
                c.Color = Drawing.Color.Red
            ElseIf chandbox.SelectedItem = "violet" Then
                c.Color = Drawing.Color.Violet
            ElseIf chandbox.SelectedItem = "white" Then
                c.Color = Drawing.Color.White
            ElseIf chandbox.SelectedItem = "yellow" Then
                c.Color = Drawing.Color.Yellow
            End If

Code for deleting making another hand so that it seems that the hand is moving/rotating
            If cclockbox.SelectedItem = "aliceblue" Then
                b.Color = Drawing.Color.AliceBlue
            ElseIf cclockbox.SelectedItem = "black" Then
                b.Color = Drawing.Color.Black
            ElseIf cclockbox.SelectedItem = "blue" Then
                b.Color = Drawing.Color.Blue
            ElseIf cclockbox.SelectedItem = "chocolate" Then
                b.Color = Drawing.Color.Chocolate
            ElseIf cclockbox.SelectedItem = "crimson" Then
                b.Color = Drawing.Color.Crimson
            ElseIf cclockbox.SelectedItem = "gold" Then
                b.Color = Drawing.Color.Gold
            ElseIf cclockbox.SelectedItem = "green" Then
                b.Color = Drawing.Color.Green
            ElseIf cclockbox.SelectedItem = "maroon" Then
                b.Color = Drawing.Color.Maroon
            ElseIf cclockbox.SelectedItem = "orange" Then
                b.Color = Drawing.Color.Orange
            ElseIf cclockbox.SelectedItem = "pink" Then
                b.Color = Drawing.Color.Pink
            ElseIf cclockbox.SelectedItem = "red" Then
                b.Color = Drawing.Color.Red
            ElseIf cclockbox.SelectedItem = "violet" Then
                b.Color = Drawing.Color.Violet
            ElseIf cclockbox.SelectedItem = "white" Then
                b.Color = Drawing.Color.White
            ElseIf cclockbox.SelectedItem = "yellow" Then
                b.Color = Drawing.Color.Yellow
            End If

Code for selecting the Width of the line(hand of a clock)
            If whandbox.SelectedItem = "1" Then
                c.Width = 1
            ElseIf whandbox.SelectedItem = "2" Then
                c.Width = 2
            ElseIf whandbox.SelectedItem = "3" Then
                c.Width = 3
            ElseIf whandbox.SelectedItem = "4" Then
                c.Width = 4
            ElseIf whandbox.SelectedItem = "5" Then
                c.Width = 5
            ElseIf whandbox.SelectedItem = "6" Then
                c.Width = 6
            ElseIf whandbox.SelectedItem = "7" Then
                c.Width = 7
            ElseIf whandbox.SelectedItem = "8" Then
                c.Width = 8
            ElseIf whandbox.SelectedItem = "9" Then
                c.Width = 9
            ElseIf whandbox.SelectedItem = "10" Then
                c.Width = 10
            End If

Code for width of another hand
            If whandbox.SelectedItem = "1" Then
                b.Width = 1
            ElseIf whandbox.SelectedItem = "2" Then
                b.Width = 2
            ElseIf whandbox.SelectedItem = "3" Then
                b.Width = 3
            ElseIf whandbox.SelectedItem = "4" Then
                b.Width = 4
            ElseIf whandbox.SelectedItem = "5" Then
                b.Width = 5
            ElseIf whandbox.SelectedItem = "6" Then
                b.Width = 6
            ElseIf whandbox.SelectedItem = "7" Then
                b.Width = 7
            ElseIf whandbox.SelectedItem = "8" Then
                b.Width = 8
            ElseIf whandbox.SelectedItem = "9" Then
                b.Width = 9
            ElseIf whandbox.SelectedItem = "10" Then
                b.Width = 10
            End If

Code for chosing the Background color of the clock/panel
            If cclockbox.SelectedItem = "aliceblue" Then
                clock.BackColor = color.AliceBlue
            ElseIf cclockbox.SelectedItem = "black" Then
                clock.BackColor = color.Black
            ElseIf cclockbox.SelectedItem = "blue" Then
                clock.BackColor = color.Blue
            ElseIf cclockbox.SelectedItem = "chocolate" Then
                clock.BackColor = color.Chocolate
            ElseIf cclockbox.SelectedItem = "crimson" Then
                clock.BackColor = color.Crimson
            ElseIf cclockbox.SelectedItem = "gold" Then
                clock.BackColor = color.Gold
            ElseIf cclockbox.SelectedItem = "green" Then
                clock.BackColor = color.Green
            ElseIf cclockbox.SelectedItem = "maroon" Then
                clock.BackColor = color.Maroon
            ElseIf cclockbox.SelectedItem = "orange" Then
                clock.BackColor = color.Orange
            ElseIf cclockbox.SelectedItem = "pink" Then
                clock.BackColor = color.Pink
            ElseIf cclockbox.SelectedItem = "red" Then
                clock.BackColor = color.Red
            ElseIf cclockbox.SelectedItem = "violet" Then
                clock.BackColor = color.Violet
            ElseIf cclockbox.SelectedItem = "white" Then
                clock.BackColor = color.White
            ElseIf cclockbox.SelectedItem = "yellow" Then
                clock.BackColor = color.Yellow
            End If

 Code for choosing the Seperation Between Consecutive Positions Of The Hand

            If sepbox.SelectedItem = "4" Then
                h = 4
            ElseIf sepbox.SelectedItem = "5" Then
                s = 5
            ElseIf sepbox.SelectedItem = "8" Then
                h = 8
            ElseIf sepbox.SelectedItem = "10" Then
                h = 10
            ElseIf sepbox.SelectedItem = "16" Then
                h = 16
            ElseIf sepbox.SelectedItem = "20" Then
                h = 20
            ElseIf sepbox.SelectedItem = "25" Then
                h = 25
            ElseIf sepbox.SelectedItem = "40" Then
                h = 40
            ElseIf sepbox.SelectedItem = "50" Then
                h = 50
            ElseIf sepbox.SelectedItem = "80" Then
                h = 80
            ElseIf sepbox.SelectedItem = "100" Then
                h = 100

            End If

Code for choosing the speed of rotation
            If speedbox.SelectedItem = "Very Fast" Then
                sp = 50
            ElseIf speedbox.SelectedItem = "Fast" Then
                sp = 100
            ElseIf speedbox.SelectedItem = "Medium" Then
                sp = 1000
            ElseIf speedbox.SelectedItem = "Slow" Then
                sp = 1500
            ElseIf speedbox.SelectedItem = "Very Slow" Then
                sp = 10000
            End If

Codes for making the clock visible and other combo box, labes invisible
            clock.Visible = True
            pstf.Visible = False
            chand.Visible = False
            chandbox.Visible = False
            whand.Visible = False
            whandbox.Visible = False
            face.Visible = False
            cclockbox.Visible = False
            sep.Visible = False
            sepbox.Visible = False
            speed.Visible = False
            speedbox.Visible = False
            dir.Visible = False
            dirbox.Visible = False
            Start.Visible = False

Codes for selecting the rotation of hand and for starting the clock.
            g = Me.CreateGraphics
            g = clock.CreateGraphics
            If dirbox.SelectedItem = "Clock Wise" Then
                cw()
            ElseIf dirbox.SelectedItem = "Anti-Clock Wise" Then
                acw()
            End If
        End If
              
Codes for starting the clock in clockwise direction:
Private Sub cw()
        While s = 0
            For x1 = h To 400 Step h
                g.DrawLine(c, 200, 200, x1, 0)
                requiredpausetime = sp
                t1 = Now
                numberofmilliseconds = 0
                Do Until (numberofmilliseconds >= requiredpausetime)
                    t2 = Now
                    pausetime = t2 - t1
                    numberofmilliseconds = pausetime.TotalMilliseconds
                Loop
                g.DrawLine(b, 200, 200, x1, 0)
            Next x1
            For y1 = h To 400 Step h
                g.DrawLine(c, 200, 200, 400, y1)
                requiredpausetime = sp
                t1 = Now
                numberofmilliseconds = 0
                Do Until (numberofmilliseconds >= requiredpausetime)
                    t2 = Now
                    pausetime = t2 - t1
                    numberofmilliseconds = pausetime.TotalMilliseconds
                Loop
                g.DrawLine(b, 200, 200, 400, y1)
            Next y1
            For x2 = 400 - h To 0 Step -h
                g.DrawLine(c, 200, 200, x2, 400)
                requiredpausetime = sp
                t1 = Now
                numberofmilliseconds = 0
                Do Until (numberofmilliseconds >= requiredpausetime)
                    t2 = Now
                    pausetime = t2 - t1
                    numberofmilliseconds = pausetime.TotalMilliseconds
                Loop
                g.DrawLine(b, 200, 200, x2, 400)
            Next x2
            For y2 = 400 - h To 0 Step -h
                g.DrawLine(c, 200, 200, 0, y2)
                requiredpausetime = sp
                t1 = Now
                numberofmilliseconds = 0
                Do Until (numberofmilliseconds >= requiredpausetime)
                    t2 = Now
                    pausetime = t2 - t1
                    numberofmilliseconds = pausetime.TotalMilliseconds
                Loop
                g.DrawLine(b, 200, 200, 0, y2)
            Next y2
        End While

    End Sub

Coding for starting the clock in anti- clock wise direction:
Private Sub acw()
        While s = 0
            For y1 = h To 400 Step h
                g.DrawLine(c, 200, 200, 0, y1)
                requiredpausetime = sp
                t1 = Now
                numberofmilliseconds = 0
                Do Until (numberofmilliseconds >= requiredpausetime)
                    t2 = Now
                    pausetime = t2 - t1
                    numberofmilliseconds = pausetime.TotalMilliseconds
                Loop
                g.DrawLine(b, 200, 200, 0, y1)
            Next y1
            For x1 = h To 400 Step h
                g.DrawLine(c, 200, 200, x1, 400)
                requiredpausetime = sp
                t1 = Now
                numberofmilliseconds = 0
                Do Until (numberofmilliseconds >= requiredpausetime)
                    t2 = Now
                    pausetime = t2 - t1
                    numberofmilliseconds = pausetime.TotalMilliseconds
                Loop
                g.DrawLine(b, 200, 200, x1, 400)
            Next x1
            For y2 = 400 - h To 0 Step -h
                g.DrawLine(c, 200, 200, 400, y2)
                requiredpausetime = sp
                t1 = Now
                numberofmilliseconds = 0
                Do Until (numberofmilliseconds >= requiredpausetime)
                    t2 = Now
                    pausetime = t2 - t1
                    numberofmilliseconds = pausetime.TotalMilliseconds
                Loop
                g.DrawLine(b, 200, 200, 400, y2)
            Next y2

            For x2 = 400 - h To 0 Step -h
                g.DrawLine(c, 200, 200, x2, 0)
                requiredpausetime = sp
                t1 = Now
                numberofmilliseconds = 0
                Do Until (numberofmilliseconds >= requiredpausetime)
                    t2 = Now
                    pausetime = t2 - t1
                    numberofmilliseconds = pausetime.TotalMilliseconds
                Loop
                g.DrawLine(b, 200, 200, x2, 0)
            Next x2
        End While
    End Sub
    Private Sub close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles close.Click
        Stop
    End Sub 
End Class

0 comments: