06 February 2017

Cara Membuat Traffic Light Sederhana dengan Visual Basic

Siapkan VB dan langsung meluncur membuat form seperti ini:



Setelah itu pastikan code-nya seperti ini
Private Sub Command1_Click()
Timer1.Interval = Text3.Text
Timer2.Interval = Text1.Text
Timer3.Interval = Text2.Text
Timer1.Enabled = True
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
End Sub

Private Sub Command3_Click()
Unload Me
End Sub

Private Sub Form_Load()
Shape2.FillColor = &H808080
Shape3.FillColor = &H808080
Shape4.FillColor = &H808080
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
End Sub

Private Sub Timer1_Timer()
If Shape2.FillColor = &H808080 Then
Shape2.FillColor = &HFF&
Shape3.FillColor = &H808080
Shape4.FillColor = &H808080
End If
Timer1.Enabled = False
Timer2.Enabled = True
Timer3.Enabled = False
End Sub

Private Sub Timer2_Timer()
If Shape3.FillColor = &H808080 Then
Shape2.FillColor = &H808080
Shape3.FillColor = &HFFFF&
Shape4.FillColor = &H808080
End If
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = True
End Sub

Private Sub Timer3_Timer()
If Shape4.FillColor = &H808080 Then
Shape2.FillColor = &H808080
Shape3.FillColor = &H808080
Shape4.FillColor = &HFF00&
End If
Timer1.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
End Sub



Semoga dapat mengembangkannya ya.

No comments:

Post a Comment