主题:菜鸟请教交通灯的程序
刚学VB没有多久,菜鸟自己编了个最初级的红绿交通灯的程序,各位高手取笑了!还请指正!
界面如图:
Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Shape1.BorderWidth = 6
Shape2.BorderWidth = 6
Shape3.BorderWidth = 6
Shape1.FillStyle = 0
Shape2.FillStyle = 0
Shape3.FillStyle = 0
Shape1.FillColor = vbBlack
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
Shape1.Visible = False
Shape2.Visible = False
Shape3.Visible = False
End Sub
Private Sub Option1_Click()
Label1.Caption = 10
Timer1.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
Shape1.Visible = True
Shape2.Visible = False
Shape3.Visible = False
Shape1.FillColor = vbRed
End Sub
Private Sub Option2_Click()
Label1.Caption = 10
Timer1.Enabled = False
Timer2.Enabled = True
Timer3.Enabled = False
Shape1.Visible = True
Shape2.Visible = True
Shape3.Visible = False
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
End Sub
Private Sub Option3_Click()
Label1.Caption = 10
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = True
Shape1.Visible = True
Shape2.Visible = True
Shape3.Visible = True
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Str(Val(Label1.Caption) - 1)
If Label1.Caption = 0 And Shape1.FillColor = vbRed Then
Label1.Caption = "10"
Shape1.FillColor = vbGreen
End If
If Label1.Caption = 0 And Shape1.FillColor = vbGreen Then
Label1.Caption = "10"
Shape1.FillColor = vbYellow
End If
If Label1.Caption = 0 And Shape1.FillColor = vbYellow Then
Label1.Caption = "10"
Shape1.FillColor = vbRed
End If
End Sub
Private Sub Timer2_Timer()
Label1.Caption = Val(Label1.Caption) - 1
If Shape1.FillColor = vbRed And Label1.Caption = 0 Then
Label1.Caption = 10
Shape1.FillColor = vbBlack
Shape2.FillColor = vbGreen
End If
If Shape2.FillColor = vbGreen And Label1.Caption = 0 Then
Label1.Caption = 10
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
End If
End Sub
Private Sub Timer3_Timer()
Label1.Caption = Val(Label1.Caption) - 1
If Shape1.FillColor = vbRed And Label1.Caption = 0 Then
Label1.Caption = 10
Shape1.FillColor = vbBlack
Shape2.FillColor = vbGreen
Shape3.FillColor = vbBlack
End If
If Shape2.FillColor = vbGreen And Label1.Caption = 0 Then
Label1.Caption = 10
Shape3.FillColor = vbYellow
Shape1.FillColor = vbBlack
Shape2.FillColor = vbBlack
End If
If Shape3.FillColor = vbYellow And Label1.Caption = 0 Then
Label1.Caption = 10
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
End If
End Sub
效果好象还能出来,让大家取笑了!还请指正!
界面如图:
Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Shape1.BorderWidth = 6
Shape2.BorderWidth = 6
Shape3.BorderWidth = 6
Shape1.FillStyle = 0
Shape2.FillStyle = 0
Shape3.FillStyle = 0
Shape1.FillColor = vbBlack
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
Shape1.Visible = False
Shape2.Visible = False
Shape3.Visible = False
End Sub
Private Sub Option1_Click()
Label1.Caption = 10
Timer1.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
Shape1.Visible = True
Shape2.Visible = False
Shape3.Visible = False
Shape1.FillColor = vbRed
End Sub
Private Sub Option2_Click()
Label1.Caption = 10
Timer1.Enabled = False
Timer2.Enabled = True
Timer3.Enabled = False
Shape1.Visible = True
Shape2.Visible = True
Shape3.Visible = False
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
End Sub
Private Sub Option3_Click()
Label1.Caption = 10
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = True
Shape1.Visible = True
Shape2.Visible = True
Shape3.Visible = True
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Str(Val(Label1.Caption) - 1)
If Label1.Caption = 0 And Shape1.FillColor = vbRed Then
Label1.Caption = "10"
Shape1.FillColor = vbGreen
End If
If Label1.Caption = 0 And Shape1.FillColor = vbGreen Then
Label1.Caption = "10"
Shape1.FillColor = vbYellow
End If
If Label1.Caption = 0 And Shape1.FillColor = vbYellow Then
Label1.Caption = "10"
Shape1.FillColor = vbRed
End If
End Sub
Private Sub Timer2_Timer()
Label1.Caption = Val(Label1.Caption) - 1
If Shape1.FillColor = vbRed And Label1.Caption = 0 Then
Label1.Caption = 10
Shape1.FillColor = vbBlack
Shape2.FillColor = vbGreen
End If
If Shape2.FillColor = vbGreen And Label1.Caption = 0 Then
Label1.Caption = 10
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
End If
End Sub
Private Sub Timer3_Timer()
Label1.Caption = Val(Label1.Caption) - 1
If Shape1.FillColor = vbRed And Label1.Caption = 0 Then
Label1.Caption = 10
Shape1.FillColor = vbBlack
Shape2.FillColor = vbGreen
Shape3.FillColor = vbBlack
End If
If Shape2.FillColor = vbGreen And Label1.Caption = 0 Then
Label1.Caption = 10
Shape3.FillColor = vbYellow
Shape1.FillColor = vbBlack
Shape2.FillColor = vbBlack
End If
If Shape3.FillColor = vbYellow And Label1.Caption = 0 Then
Label1.Caption = 10
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
Shape3.FillColor = vbBlack
End If
End Sub
效果好象还能出来,让大家取笑了!还请指正!