Membuat Stopwatch Dari Visual Basic 6.0
Untuk membuat stopwatch dari visual
basic 6.0 masukkan komponen berikut ke dalam form :
Komponen
|
Properties
|
Text1
|
Text=””, Locked=”True”
|
Timer1
|
Interval=”10”
|
Command1
|
Caption=”&Mulai”
|
Command2
|
Caption=”&Ulangi”
|
Selanjutnya masuk pada jendela coding,
dan buat koding berikut :
Dim
i As Integer
Dim
jam As Integer
Dim
menit As Integer
Dim
detik As Integer
Private
Sub command1_Click()
If
Timer1.Enabled = True Then
Timer1.Enabled
= False
Command1.Caption
= "&Lanjutkan"
Command2.Enabled
= True
Else
Timer1.Enabled
= True
Command1.Caption
= "&Berhenti"
Command2.Enabled
= False
End
If
End
Sub
Private
Sub Reset()
i
= 0
jam
= 0
menit
= 0
detik
= 0
End
Sub
Private
Sub Command2_Click()
Reset
Timer1.Enabled
= True
Command2.Enabled
= False
Command1.Caption
= "&Berhenti"
End
Sub
Private
Sub Form_Load()
Timer1.Interval
= 10
Timer1.Enabled
= False
End
Sub
Private
Sub Timer1_Timer()
If
(i < 100) Then
CetakTimer
i
= i + 1
Else
i
= 0
If
(detik < 60) Then
detik
= detik + 1
Else
detik
= 0
If
(menit < 60) Then
menit
= menit + 1
Else
menit
= 0
jam
= jam + 1
End
If
End
If
End
If
End
Sub
Private
Function TwoDigit(Angka As Integer) As String
Dim
result As String
If
(Angka < 10) Then
result
= "0" & Angka
Else
result
= Angka
End
If
TwoDigit
= result
End
Function
Private
Sub CetakTimer()
Text1.Text
= TwoDigit(jam) & ":" & TwoDigit(menit) & ":"
& TwoDigit(detik) & "." & TwoDigit(i)
End
Sub
Lalu jalankan project (F5)…
Labels: Pemrograman, Visual Basic 6.0
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home