Membuat sebuah aplikasi untuk digunakan sebagai pencatat waktu. Nama kerennya adalah Stop Watch. Pasti sudah tahu apa itu yang namanya Stop Watch, bagaimana cara bekerjanya? Disini kita akan mencoba latihan untuk membuat sebuah Stop Watch.
Tampilan desain
Komponen yang dibutuhkan
- Timer
- Button
- TextBox
- Label
- PictureBox
Untuk code program bisa dilihat dibawah ini
Kunjungi juga contoh aplikasi laporan CRUD disini
——————————————————————————————————–
Public Class Form1
Dim milseconds, seconds, minutes, hours As Integer
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If milseconds = 60 Then
milseconds = 0
seconds = seconds + 1
End If
If seconds = 60 Then
If milseconds = 60 Then
milseconds = 0
seconds = 0
minutes = minutes + 1
End If
End If
If minutes = 60 Then
If seconds = 60 Then
If milseconds = 60 Then
milseconds = 0
seconds = 0
minutes = 0
hours = hours + 1
End If
End If
End If
milseconds = milseconds + 1
TextBox1.Text = Format(hours, “00″) & “:” & Format(minutes, “00″) & “:” & Format(seconds, “00″) & “:” & Format(milseconds, “00″)
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 10
Timer1.Start()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Stop()
End Sub
Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Timer1.Stop()
TextBox1.Clear()
End Sub
End Class
No comments:
Write comments