Membuat digital stopwatch menggunakan bahasa pemrograman seperti Visual Basic spertinya udah ga asing lagi, mungkin banyak rekan-rekan sekalian yang udah bisa membuat stopwatch digital yang lebih bagus lagi, kali ini saya juga akan membagikan sedikit ilmu saya kepada teman-teman sekalian, semoga artikel ini bermanfaat.
Buatlah project baru dengan pilihan standart exe, buatlah 2 buah timer, timer ini nantinya digunakan untuk mengaktifkan jam sedangkan timer yang kedua digunakan untuk mengaktifkan stopwatch, kemudian isi kedua buah interval timer dengan nilai disesuaikan dengan kebutuhan. Selanjutnya buat 3buah commandbutton,
Button1 isi caption dengan nilai START
Button2 isi caption dengan nilai STOP
Button3 isi caption dengan nilai RESET
Sudah semuanyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa. LANJUT
Kemudian ketikkan coding (kalo malas copy paste aja) berikut pada coding editor anda dengan cara klik icon view code yang ada pada sudut kanan properties project:
Dim a As String
Dim b As String
Dim c As String
Dim x As String
Dim y As String
Dim z As String
Dim h As String
Dim m As String
Dim s As String
Dim u As String
Dim v As String
Public interval As Double
Private Sub clock_Click()
Timer1.Enabled = False
Timer2.Enabled = True
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.interval = 1
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Command3_Click()
Timer1.Enabled = False
a = "0"
b = "0"
c = "0"
x = "0"
y = "0"
z = "0"
u = "0"
v = "0"
h = a + b
m = c + x
s = y + z
'To set the display as "00:00:00.00"
Label1.Caption = h + ":" + m + ":" + s + "." + u + v
End Sub
Sub counttime()
If Val(v) < 9 Then
v = v + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(u) < 9 Then
v = 0
u = u + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(z) < 9 Then
v = 0
u = 0
z = z + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(y) < 5 Then
v = 0
u = 0
z = 0
y = y + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(x) < 9 Then
v = 0
u = 0
z = 0
y = 0
x = x + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(c) < 5 Then
v = 0
u = 0
z = 0
y = 0
x = 0
c = c + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(b) < 9 Then
v = 0
u = 0
z = 0
y = 0
x = 0
c = 0
b = b + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(b) < 9 Then
v = 0
u = 0
z = 0
y = 0
x = 0
c = 0
b = b + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
ElseIf Val(a) < 9 Then
v = 0
u = 0
z = 0
y = 0
x = 0
c = 0
b = 0
a = a + 1
Label1.Caption = a + b + ":" + c + x + ":" + y + z + "." + u + v
End If
End Sub
Private Sub dat_Click()
Label1.Caption = Date
Timer2.Enabled = False
End Sub
Private Sub Form_Load()
a = "0"
b = "0"
c = "0"
x = "0"
y = "0"
z = "0"
u = 0
v = 0
h = a + b
m = c + x
s = y + z
'To set the display as "00:00:00.00"
Label1.Caption = h + ":" + m + ":" + s + "." + u + v
End Sub
Private Sub stopwc_Click()
Timer2.Enabled = False
a = "0"
b = "0"
c = "0"
x = "0"
y = "0"
z = "0"
u = "0"
v = "0"
h = a + b
m = c + x
s = y + z
Label1.Caption = h + ":" + m + ":" + s + "." + u + v
End Sub
Private Sub Timer1_Timer()
counttime
End Sub
Private Sub Timer2_Timer()
Label1.Caption = Time
End Sub
Setelah itu klik tombol start atau tekan F5 pada keyboard anda. Jika ingin melakukan hasil yang maksimal silahkan kreasi anda.
0 komentar:
Posting Komentar