Stopwatch in VB6
This is a stopwatch application in VB6 that uses the Timer control. The user has the option to start, stop and reset the stopwatch.
First create the above design of your program in the form designer and then copy the below code into the code window of the vb.
Code:
Dim smallsec As Integer, sec As Integer, min As Integer
Dim hour As Integer
________________________________________________
Private Sub cmdReset_Click()
cmdStart.Caption = "Start"
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Text1.Text = Format(0, "00")
Text2.Text = Format(0, "00")
Text3.Text = Format(0, "00")
End Sub
________________________________________________
Private Sub cmdStart_Click()
If cmdStart.Caption = "Start" Then
cmdStart.Caption = "Stop"
Else
cmdStart.Caption = "Start"
End If
If cmdStart.Caption = "Stop" Then
Timer3.Enabled = True
Timer2.Enabled = True
Timer1.Enabled = True
Else
Timer3.Enabled = False
Timer2.Enabled = False
Timer1.Enabled = False
End If
End Sub
________________________________________________
Private Sub Timer1_Timer()
If txtMinute.Text < 59 Then
txtMinute.Text = Format(txtMinute.Text + 1, "00")
Else
txtMinute.Text = Format(0, "00")
End If
End Sub
________________________________________________
Private Sub Timer2_Timer()
If txtSecond.Text < 59 Then
txtSecond.Text = Format(txtSecond.Text + 1, "00")
Else
txtSecond.Text = Format(0, "00")
End If
End Sub
________________________________________________
Private Sub Timer3_Timer()
If txtMiniSecond.Text < 99 Then
txtMiniSecond.Text = Format(txtMiniSecond.Text + 1, "00")
Else
txtMiniSecond.Text = Format(0, "00")
End If
End Sub
Dim hour As Integer
________________________________________________
Private Sub cmdReset_Click()
cmdStart.Caption = "Start"
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Text1.Text = Format(0, "00")
Text2.Text = Format(0, "00")
Text3.Text = Format(0, "00")
End Sub
________________________________________________
Private Sub cmdStart_Click()
If cmdStart.Caption = "Start" Then
cmdStart.Caption = "Stop"
Else
cmdStart.Caption = "Start"
End If
If cmdStart.Caption = "Stop" Then
Timer3.Enabled = True
Timer2.Enabled = True
Timer1.Enabled = True
Else
Timer3.Enabled = False
Timer2.Enabled = False
Timer1.Enabled = False
End If
End Sub
________________________________________________
Private Sub Timer1_Timer()
If txtMinute.Text < 59 Then
txtMinute.Text = Format(txtMinute.Text + 1, "00")
Else
txtMinute.Text = Format(0, "00")
End If
End Sub
________________________________________________
Private Sub Timer2_Timer()
If txtSecond.Text < 59 Then
txtSecond.Text = Format(txtSecond.Text + 1, "00")
Else
txtSecond.Text = Format(0, "00")
End If
End Sub
________________________________________________
Private Sub Timer3_Timer()
If txtMiniSecond.Text < 99 Then
txtMiniSecond.Text = Format(txtMiniSecond.Text + 1, "00")
Else
txtMiniSecond.Text = Format(0, "00")
End If
End Sub