Jumat, 06 September 2013

VB 6.0 - membuat program lampu lalu lintas


 nah pada kesempatan kali ini saya ingin memberi tau sedikit informasi mengenai code/script untuk membuat traffict light menggunakan vb.6



Berikut adalah script untuk
program di atas :

dim timer(1 To 3) As Integer
Private Sub Command1_Click()


timer(1) = Val(Text1.Text)
timer(2) = Val(Text2.Text)
timer(3) = Val(Text3.Text)
Timer1.Enabled = True
Command1.Enabled = False
End Sub
Private Sub Command3_Click()
Command1.Enabled = True
Command3.Enabled = False
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
End Sub
Private Sub Timer1_Timer()
If timer(1) > 0 Then
timer(1) = timer(1) - 1
Shape1.BackColor = vbRed
Shape2.BackColor = vbWhite
Shape3.BackColor = vbWhite
Label1.Caption = timer(1)
Label1.ForeColor = vbRed
Else
Timer1.Enabled = False
Timer2.Enabled = True
End If
End Sub
Private Sub Timer2_Timer()
If timer(2) > 0 Then
timer(2) = timer(2) - 1
Shape1.BackColor = vbWhite
Shape2.BackColor = vbYellow
Shape3.BackColor = vbWhite
Label1.Caption = timer(2)
Label1.ForeColor = vbYellow
Else
Timer2.Enabled = False
Timer3.Enabled = True
End If
End Sub
Private Sub Timer3_Timer()
If timer(3) > 0 Then
timer(3) = timer(3) - 1
Shape1.BackColor = vbWhite
Shape2.BackColor = vbWhite
Shape3.BackColor = vbGreen
Label1.Caption = timer(3)
Label1.ForeColor = vbGreen
Else
Timer3.Enabled = False
Command1_Click
End If
End Sub


Selamat mengerjakan & keep try

Tidak ada komentar:

Posting Komentar