SlideShare a Scribd company logo
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

More Related Content

DOCX
Codes
PDF
Linear Search Program in Visual Basic 2008
PDF
Binary Search Program in Visual Basic 2008
TXT
Send email
PDF
Calculator code
PDF
Intro to ReactiveCocoa
PDF
Inventory management
PDF
ReactiveCocoa and Swift, Better Together
Codes
Linear Search Program in Visual Basic 2008
Binary Search Program in Visual Basic 2008
Send email
Calculator code
Intro to ReactiveCocoa
Inventory management
ReactiveCocoa and Swift, Better Together

Similar to Stop watch and array (20)

PDF
PROGRAMA DE EJEMPLO
DOCX
Simulador
DOCX
Simulador
PDF
Www.martin2k.co.uk vb6 tips_vb_41
PPTX
Dinesh Narayan ,Final year BCA ,Dezyne E'cole College
PPTX
PDF
Visual Basic(Vb) practical
PPTX
Timer control
DOC
9b4c1 vb(pd)
DOC
9b4c1 vb(pd) (2)
PPTX
Timer control and Tool Strip C#
PDF
19.Advanced Visual Basic Lab.pdf
PPTX
Design for edp
DOCX
Docimp
PPTX
Creating the Timer on visual basic
DOCX
Vbreport program
DOCX
AlarmClockAlarmClockAlarmClock.Designer.vbGlobal.Microsoft..docx
DOCX
Vbreport
PDF
03 fade
PPTX
Timer programming
PROGRAMA DE EJEMPLO
Simulador
Simulador
Www.martin2k.co.uk vb6 tips_vb_41
Dinesh Narayan ,Final year BCA ,Dezyne E'cole College
Visual Basic(Vb) practical
Timer control
9b4c1 vb(pd)
9b4c1 vb(pd) (2)
Timer control and Tool Strip C#
19.Advanced Visual Basic Lab.pdf
Design for edp
Docimp
Creating the Timer on visual basic
Vbreport program
AlarmClockAlarmClockAlarmClock.Designer.vbGlobal.Microsoft..docx
Vbreport
03 fade
Timer programming
Ad

Recently uploaded (20)

PDF
Basic Mud Logging Guide for educational purpose
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
master seminar digital applications in india
PDF
01-Introduction-to-Information-Management.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Insiders guide to clinical Medicine.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Institutional Correction lecture only . . .
Basic Mud Logging Guide for educational purpose
Pharmacology of Heart Failure /Pharmacotherapy of CHF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
O7-L3 Supply Chain Operations - ICLT Program
Renaissance Architecture: A Journey from Faith to Humanism
Microbial diseases, their pathogenesis and prophylaxis
master seminar digital applications in india
01-Introduction-to-Information-Management.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Insiders guide to clinical Medicine.pdf
Supply Chain Operations Speaking Notes -ICLT Program
VCE English Exam - Section C Student Revision Booklet
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Pharma ospi slides which help in ospi learning
Anesthesia in Laparoscopic Surgery in India
human mycosis Human fungal infections are called human mycosis..pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Institutional Correction lecture only . . .
Ad

Stop watch and array

  • 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: 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.
  • 5. Program:-2 Stopwatch (without comment) (With Lap And Manual Reverse) You will Need 3 Timer
  • 7. Timer1 interval: 1000 Timer2 interval: 1000 Timer3 interval: 600 it is only used for text blinking
  • 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.