主题:菜鸟请教如何让用户自己输入红绿灯切换时间?(改进了的交通信号灯程序)
将红绿灯程序改进了一下,界面如图示。程序已经运行通过,具体代码如下:
Private Sub Form_Load()
For i = 0 To 4
Image1(i).Visible = False
Line1(i).BorderColor = &HC0C0C0 '斑马线的颜色
Next i
Shape1.Shape = 3
Shape2.Shape = 3
Shape1.FillStyle = 0
Shape2.FillStyle = 0
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
Form1.BackColor = vbWhite
Timer1.Enabled = False
Timer1.Interval = 125 '图片每隔125毫秒切换一张
'红绿灯5秒钟变换一次
End Sub
Private Static Sub Timer1_Timer() '设置人走动的图片
i = i + 1
Image2.Picture = Image1(i).Picture
If i >= 4 Then i = 0
End Sub
Private Sub Timer2_Timer() '设置行人红绿灯的状态
If Shape1.FillColor = vbRed Then '亮绿灯
Shape1.FillColor = vbBlack
Shape2.FillColor = vbGreen
Timer1.Enabled = True '行人可以行走
Else '亮红灯
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
Timer1.Enabled = False '行人不能行走
End If
End Sub
以上程序完全可以运行成功。我想再完善一下,让用户自己输入红绿灯切换时间,于是在界面上加了个文本框text1,然后在form_load事件中将从前的Timer2.Interval = 5000这一语句替换成了Timer2.Interval =val(text1.text),但是,运行不出效果!
请教!谢谢!
Private Sub Form_Load()
For i = 0 To 4
Image1(i).Visible = False
Line1(i).BorderColor = &HC0C0C0 '斑马线的颜色
Next i
Shape1.Shape = 3
Shape2.Shape = 3
Shape1.FillStyle = 0
Shape2.FillStyle = 0
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
Form1.BackColor = vbWhite
Timer1.Enabled = False
Timer1.Interval = 125 '图片每隔125毫秒切换一张
'红绿灯5秒钟变换一次
End Sub
Private Static Sub Timer1_Timer() '设置人走动的图片
i = i + 1
Image2.Picture = Image1(i).Picture
If i >= 4 Then i = 0
End Sub
Private Sub Timer2_Timer() '设置行人红绿灯的状态
If Shape1.FillColor = vbRed Then '亮绿灯
Shape1.FillColor = vbBlack
Shape2.FillColor = vbGreen
Timer1.Enabled = True '行人可以行走
Else '亮红灯
Shape1.FillColor = vbRed
Shape2.FillColor = vbBlack
Timer1.Enabled = False '行人不能行走
End If
End Sub
以上程序完全可以运行成功。我想再完善一下,让用户自己输入红绿灯切换时间,于是在界面上加了个文本框text1,然后在form_load事件中将从前的Timer2.Interval = 5000这一语句替换成了Timer2.Interval =val(text1.text),但是,运行不出效果!
请教!谢谢!