4. Code Starts Here:
Public Class Form1
'sum of Number Without Array
Dim s, avg, i As Integer
Private Sub btnC_Click(sender As Object, e As EventArgs) Handles btnC.Click
'clear the controls
lstN.Items.Clear()
txtN.Clear()
lblAvg.Text = ""
lblSum.Text = ""
'reset the values
s = avg = i = 0
End Sub
Private Sub txtN_KeyDown(sender As Object, e As KeyEventArgs) Handles txtN.KeyDown
'check if user pressed an 'Enter Key'
If e.KeyCode = Keys.Enter Then
lstN.Items.Add(txtN.Text) 'add the number in listbox
i = i + 1 'only average
s = s + txtN.Text 'use for sum
'show the answar in label
lblSum.Text = s 'sum label
lblAvg.Text = s / i 'average label
txtN.Text = "" 'clear the textbox for next input
End If
End Sub
End Class
Code Ends Here.
8. Code Starts Here:
Public Class Form1
Dim ss, mm, hh As Integer
Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
ResetColor()
ss = 0 : mm = 0 : hh = 0
lblH.Text = "00"
lblM.Text = "00"
lblS.Text = "00"
btnPlayPause.Text = "Start"
Timer1.Enabled = False
End Sub
Private Sub btnPlayPause_Click(sender As Object, e As EventArgs) Handles btnPlayPause.Click
Timer2.Enabled = False
If Timer1.Enabled Then
Timer1.Enabled = False
btnPlayPause.Text = "Resume"
Else
Timer1.Enabled = True
btnPlayPause.Text = "Pause"
End If
End Sub
Private Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
ResetColor()
Timer1.Enabled = False
Dim LapValueS As Integer
LapValueS = CInt(txtGo.Text)
mm = LapValueS 60
ss = LapValueS Mod 60
lblS.Text = ss
lblM.Text = mm
Timer2.Enabled = True
End Sub
Private Sub btnLap_Click(sender As Object, e As EventArgs) Handles btnLap.Click
Dim LapT As String
LapT = hh & ":" & mm & ":" & ss
lstLaps.Items.Add(LapT)
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
ss = ss + 1
lblS.Text = ss
If ss >= 59 Then
mm = mm + 1
lblM.Text = mm
ss = 0
9. If mm >= 59 Then
hh = hh + 1
lblH.Text = hh
mm = 0
End If
End If
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
ss = ss - 1
If ss < 0 Then
ss = 59
mm = mm - 1
lblM.Text = mm
End If
lblS.Text = ss
If ss = 0 And mm = 0 Then
Timer2.Enabled = False
Timer3.Enabled = True
End If
End Sub
Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
If lblS.ForeColor <> Color.Black Then
lblH.ForeColor = Color.Black
lblM.ForeColor = Color.Black
lblS.ForeColor = Color.Black
ElseIf lblS.ForeColor = Color.Black Then
lblH.ForeColor = Color.Tomato
lblM.ForeColor = Color.Tomato
lblS.ForeColor = Color.Tomato
End If
End Sub
Private Sub ResetColor()
lblH.ForeColor = Color.DarkRed
lblM.ForeColor = Color.ForestGreen
lblS.ForeColor = Color.RoyalBlue
Timer3.Enabled = False
End Sub
End Class
Code Ends Here.