Write a visual basic program for stopwatch:-
Design Window:-
Code:-
Dim starttime As Date
Dim s As Date
Private Sub Reset_Click()
Timer1.Enabled = False
starttime = Now
Timer1.Enabled = True
End Sub
Private Sub Start_Click()
starttime = Now
Timer1.Enabled = True
End Sub
Private Sub Stop_Click()
Timer1.Enabled = False
Label1.Caption = ""
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
End Sub
Private Sub Pause_Click()
If Pause.Caption = "Pause" Then
Timer1.Enabled = False
s1 = Label1.Caption
Pause.Caption = "Play"
End If
If Pause.Caption = "Play" Then
Label1.Caption = s1
Timer1.Enabled = True
End If
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Format$(Now - starttime, "hh:mm:ss:ms")
End Sub
============================================
OUTPUT
Design Window:-
Code:-
Dim starttime As Date
Dim s As Date
Private Sub Reset_Click()
Timer1.Enabled = False
starttime = Now
Timer1.Enabled = True
End Sub
Private Sub Start_Click()
starttime = Now
Timer1.Enabled = True
End Sub
Private Sub Stop_Click()
Timer1.Enabled = False
Label1.Caption = ""
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
End Sub
Private Sub Pause_Click()
If Pause.Caption = "Pause" Then
Timer1.Enabled = False
s1 = Label1.Caption
Pause.Caption = "Play"
End If
If Pause.Caption = "Play" Then
Label1.Caption = s1
Timer1.Enabled = True
End If
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Format$(Now - starttime, "hh:mm:ss:ms")
End Sub
============================================
OUTPUT