主题:菜鸟请教红绿灯程序中的变量
如下一个交通红绿灯的程序
Option Explicit
Dim i As Byte, Tim As Byte, Tim1 As Byte
Private Sub Form_Load()
For i = 0 To 2
Timer1.Interval = 1000
Shape1(i).FillStyle = 0
Shape1(i).BorderWidth = 3
Next i
Label1.BackColor = vbBlack
Label1.ForeColor = vbRed
Label1.FontSize = 20
Tim = 0
End Sub
Private Sub Timer1_Timer()
Tim = Tim + 1
Tim = Tim Mod 26
Select Case Tim
Case 1 To 10 '红灯亮
Label1.Caption = 11 - Tim
Shape1(0).FillColor = vbRed
Shape1(1).FillColor = vbBlack
Shape1(2).FillColor = vbBlack
Case 0, 11 To 13, 24 To 25 '黄灯亮
Tim1 = 27 - Tim
Label1.Caption = Tim1 Mod 13
Shape1(0).FillColor = vbBlack
Shape1(1).FillColor = vbYellow
Shape1(2).FillColor = vbBlack
Case 14 To 23 '绿灯亮
Label1.Caption = 24 - Tim
Shape1(0).FillColor = vbBlack
Shape1(1).FillColor = vbBlack
Shape1(2).FillColor = vbGreen
End Select
End Sub
请问这个程序中并没有设置tim或timer事件为静态的,但怎么能每次都"记住"上一次的结果呢?
Option Explicit
Dim i As Byte, Tim As Byte, Tim1 As Byte
Private Sub Form_Load()
For i = 0 To 2
Timer1.Interval = 1000
Shape1(i).FillStyle = 0
Shape1(i).BorderWidth = 3
Next i
Label1.BackColor = vbBlack
Label1.ForeColor = vbRed
Label1.FontSize = 20
Tim = 0
End Sub
Private Sub Timer1_Timer()
Tim = Tim + 1
Tim = Tim Mod 26
Select Case Tim
Case 1 To 10 '红灯亮
Label1.Caption = 11 - Tim
Shape1(0).FillColor = vbRed
Shape1(1).FillColor = vbBlack
Shape1(2).FillColor = vbBlack
Case 0, 11 To 13, 24 To 25 '黄灯亮
Tim1 = 27 - Tim
Label1.Caption = Tim1 Mod 13
Shape1(0).FillColor = vbBlack
Shape1(1).FillColor = vbYellow
Shape1(2).FillColor = vbBlack
Case 14 To 23 '绿灯亮
Label1.Caption = 24 - Tim
Shape1(0).FillColor = vbBlack
Shape1(1).FillColor = vbBlack
Shape1(2).FillColor = vbGreen
End Select
End Sub
请问这个程序中并没有设置tim或timer事件为静态的,但怎么能每次都"记住"上一次的结果呢?