Stop Watch.
VB.NET
16/7/2019
12:04 AM
SUROJIT PAUL
Program:-1
Sum of Numbers
(Without array)
Label
name-> lblAvg
Button
name-> btnC
Textbox
name-> txtN
Listbox
name-> lstN
Label
name-> lblSum
Be careful when copy/paste this code.
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.
Program:-2
Stopwatch (without comment)
(With Lap And Manual Reverse)
You will Need 3 Timer
Label
Name:-lblH
Label
Name:-lblM
Label
Name:-lblS
Textbox
Name:-txtGo
Listbox
Name:-lstLaps
Button
Name:-btnGo
Button
Name:-btnReset
Button
Name:-btnLap
Button
Name:-btnPlayPause
Timer1 interval: 1000
Timer2 interval: 1000
Timer3 interval: 600 it is only used for text blinking
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
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.
Stop watch and array

Stop watch and array

  • 1.
  • 2.
  • 3.
    Label name-> lblAvg Button name-> btnC Textbox name->txtN Listbox name-> lstN Label name-> lblSum Be careful when copy/paste this code.
  • 4.
    Code Starts Here: PublicClass 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.
  • 5.
    Program:-2 Stopwatch (without comment) (WithLap And Manual Reverse) You will Need 3 Timer
  • 6.
  • 7.
    Timer1 interval: 1000 Timer2interval: 1000 Timer3 interval: 600 it is only used for text blinking
  • 8.
    Code Starts Here: PublicClass 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.