vb问题6 急急急急

来源:百度知道 编辑:UC知道 时间:2024/05/18 08:43:00
13.窗体上有两个图片框,名称为
P1、P2,分别用来表示信号灯和汽车,其中在P1中轮流装入“黄灯.ico”、
“红灯.ico”、“绿灯.ico”文件来实现信号灯的切换;还有两个计时器
Timer1和Timer2,Timer1用于变换信号灯,黄灯1秒,红灯2秒,绿灯3秒;
Timer2用于控制汽车向左移动。运行时,信号灯不断变换,单击“开车”按
钮,汽车开始移动,如果移动到信号灯前或信号灯下,遇到红灯或黄灯,则
停止移动,当变为绿灯后再继续移动。在窗体中已经给出了全部控件和程序,
则程序不完整,要求阅读程序并去掉程序中的注释符,把程序中的?改为正
确的内容,使其实现上述功能,但不能修改程序中的其他部分,也不能修改
控件的属性。
Dim a%, b As Boolean

Private Sub C1_Click()
' Timer2.Enabled = ?
b = True
End Sub

Private Sub Timer1_Timer()
a = a + 1
If a > 6 Then
a = 1
End If
Select Case a
Case 1
P1.Picture = LoadPicture("黄灯.ico")
Case 2, 3
P1.Picture = LoadPicture("红灯.ico")
Case 4, 5, 6
' P1.Picture = LoadPicture("?")
If b Then Timer2.Enabled = True
End Select
End Sub

Private Sub Timer2_Timer()
If (a

13:
Dim a%, b As Boolean

Private Sub C1_Click()
Timer2.Enabled = true '车往左开
b = True
End Sub

Private Sub Timer1_Timer()
a = a + 1
If a > 6 Then
a = 1
End If
Select Case a
Case 1
P1.Picture = LoadPicture("黄灯.ico")
Case 2, 3
P1.Picture = LoadPicture("红灯.ico")
Case 4, 5, 6
P1.Picture = LoadPicture("绿灯.ico")
If b Then Timer2.Enabled = True
End Select
End Sub

Private Sub Timer2_Timer()
If (a < 4) And (P2.Left > P1.Left And P2.Left < P1.Left + P1.Width) Or P2.Left <= 100 Then
Timer2.Enabled = false '停止
Else
P2.Move P2.left - 10, P2.Top, P2.Width, P2.Height'为绿灯汽车前进
End If
End Sub

14
Private Sub C1_Click()
Dim strinfo As String
Open \"in6.txt\" For Input As #1
Input #1, strinfo
\'Close #1
\&