Latihan Membuat Stopwatch dengan VB 6
Pertama buka software VB 6, dan buat form1 dengan nama Stopwatch. buatlah 3 text, 2 commond dan 1 timer.
Buat :
Text : txtmili, txtsecond, txtminute
Commond : cmdstart, cmdstop
Timer : Timer1
Dengan coding sebagai berikut :
Private Sub cmdstart_Click()
txtmili.Text = "00"
txtsecond.Text = "00"
txtminute.Text = "00"
Timer1.Enabled = True
cmdstart.Enabled = False
cmdstop.Enabled = True
End Sub
Private Sub cmdstop_Click()
Timer1.Enabled = False
cmdstart.Enabled = True
cmdstop.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
cmdstop.Enabled = False
txtmili.Text = "00"
txtsecond.Text = "00"
txtminute.Text = "00"
End Sub
Private Sub Timer1_Timer()
txtmili.Text = Val(txtmili.Text) + 1
If Len(txtmili.Text) = 1 Then txtmili.Text = "0" & txtmili.Text
If txtmili.Text = "60" Then
txtmili.Text = "00"
txtsecond.Text = Val(txtsecond.Text) + 1
If Len(txtsecond.Text) = 1 Then txtsecond.Text = "0" & txtsecond.Text
End If
If txtsecond.Text = "60" Then
txtsecond.Text = "00"
txtminute.Text = Val(txtminute.Text) + 1
If Len(txtminute.Text) = 1 Then txtminute.Text = "0" & txtminute.Text
End If
End Sub



Komentar
Posting Komentar