Timer Visual Basic (LA2)
Kali ini saya akan membagikan ilmu yang telah saya dapat yaitu tentang timer pada visual basic. Timer merupakan sebuah tool yang digunakan untuk mengatur jeda waktu dalam pembuatan sebuah program. langsung saja dicoba kodingan dibawah ini pada visual basic anda :
Form1
Private Sub Timer1_Timer()
Label3.Caption = Label3.Caption + 1
If Label3.Caption = 60 Then
Label3.Caption = 0
Label4.Caption = Label4.Caption + 1
End If
End Sub
Form2
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer2.Enabled = True
End Sub
Private Sub Command3_Click()
Timer4.Enabled = True
End Sub
Private Sub Command4_Click()
Timer3.Enabled = True
End Sub
Private Sub Command5_Click()
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
End Sub
Private Sub menuexit_Click()
End
End Sub
Private Sub menuform_Click()
Form1.Show
End Sub
Private Sub Timer1_Timer()
Shape1.Top = Shape1.Top - 15
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
If Shape1.Top = 0 Then
Timer1.Enabled = False
Timer3.Enabled = True
End If
End Sub
Private Sub Timer2_Timer()
Shape1.Left = Shape1.Left - 15
Timer1.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
If Shape1.Left = 0 Then
Timer2.Enabled = False
Timer4.Enabled = True
End If
End Sub
Private Sub Timer3_Timer()
Shape1.Top = Shape1.Top + 15
Timer1.Enabled = False
Timer2.Enabled = False
Timer4.Enabled = False
If Shape1.Top = 5880 Then
Timer3.Enabled = False
Timer1.Enabled = True
End If
End Sub
Private Sub Timer4_Timer()
Shape1.Left = Shape1.Left + 15
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
If Shape1.Left = 4560 Then
Timer4.Enabled = False
Timer2.Enabled = True
End If
End Sub
Private Sub Warna2_Click()
Shape1.FillColor = vbBlue
End Sub
Private Sub Warna3_Click()
Shape1.FillColor = vbRed
End Sub
Untuk kalian yang sudah mecoba, jika belum mengerti dari logika kodingan ini bisa di download file ini. Downlaod disini.
LISTING PROGRAM
Form1
Private Sub Timer1_Timer()
Label3.Caption = Label3.Caption + 1
If Label3.Caption = 60 Then
Label3.Caption = 0
Label4.Caption = Label4.Caption + 1
End If
End Sub
Form2
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer2.Enabled = True
End Sub
Private Sub Command3_Click()
Timer4.Enabled = True
End Sub
Private Sub Command4_Click()
Timer3.Enabled = True
End Sub
Private Sub Command5_Click()
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
End Sub
Private Sub menuexit_Click()
End
End Sub
Private Sub menuform_Click()
Form1.Show
End Sub
Private Sub Timer1_Timer()
Shape1.Top = Shape1.Top - 15
Timer2.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
If Shape1.Top = 0 Then
Timer1.Enabled = False
Timer3.Enabled = True
End If
End Sub
Private Sub Timer2_Timer()
Shape1.Left = Shape1.Left - 15
Timer1.Enabled = False
Timer3.Enabled = False
Timer4.Enabled = False
If Shape1.Left = 0 Then
Timer2.Enabled = False
Timer4.Enabled = True
End If
End Sub
Private Sub Timer3_Timer()
Shape1.Top = Shape1.Top + 15
Timer1.Enabled = False
Timer2.Enabled = False
Timer4.Enabled = False
If Shape1.Top = 5880 Then
Timer3.Enabled = False
Timer1.Enabled = True
End If
End Sub
Private Sub Timer4_Timer()
Shape1.Left = Shape1.Left + 15
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
If Shape1.Left = 4560 Then
Timer4.Enabled = False
Timer2.Enabled = True
End If
End Sub
Private Sub Warna2_Click()
Shape1.FillColor = vbBlue
End Sub
Private Sub Warna3_Click()
Shape1.FillColor = vbRed
End Sub
OUTPUT PROGRAM
Untuk kalian yang sudah mecoba, jika belum mengerti dari logika kodingan ini bisa di download file ini. Downlaod disini.
Komentar
Posting Komentar
Mari tukar pendapat, tapi jangan tukar pendapatan ;)