精華區beta Visual_Basic 關於我們 聯絡資訊
老師要我們寫一個程式 有關紅綠燈的 就是在綠燈亮5秒後 換成黃燈亮2秒 紅燈亮7秒 之後再換成綠燈5秒 我有做出來了 但是就是沒辦法讓每個燈變成老師所要求的秒數 然後 順序也完全跑掉 改了很多次 不知道自己到底哪裡錯 希望有人能夠幫我 謝謝!!! 以下是我寫的程式 希望有人能糾正我到底哪裡錯了... (其實我不大懂 Timer1.Enabled = False 這的意思 >"< ) Dim Index As Integer Private Sub Command1_Click() Set Form1.Picture = Image1(Index).Picture Index = Index + 1 If Index > 2 Then Index = 0 End Sub Private Sub Command2_Click() End End Sub Private Sub Timer1_Timer() Set Form1.Picture = Image1(0).Picture Timer1.Enabled = False Timer2.Enabled = True End Sub Private Sub Timer2_Timer() Set Form1.Picture = Image1(1).Picture Timer2.Enabled = False Timer3.Enabled = True End Sub Private Sub Timer3_Timer() Set Form1.Picture = Image1(2).Picture Timer3.Enabled = False Timer1.Enabled = True End Sub Private Sub Timer4_Timer() Label1.Caption = Time End Sub -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 210.58.168.61
BearWu:那個意思代表啟動TRUE、關閉FALSE,TIMER的功用 192.83.195.244 05/18
BearWu:有原程式嗎!!有原程式的話,提供一下吧!!比較好解 192.83.195.244 05/18
> -------------------------------------------------------------------------- < 作者: fumizuki (小獅) 看板: Visual_Basic 標題: Re: [請益] 請各位幫幫我.....(剛學VB6.0= =) 時間: Wed May 18 10:32:45 2005 '專案需一個表單,一個Timer控制項,一個Command控制項,屬性不需設定。 Dim Light As Integer, Second As Integer Private Sub Form_Load() Timer1.Interval = 1000 '每一秒更新一次燈號 Set Picture = Image1(Light).Picture '預設綠燈 End Sub Private Sub Timer1_Timer() Dim Flag As Integer Second = Second + 1 If Light = 0 Then If Second = 5 Then Light = 1: Flag = 1 '綠燈變黃燈 ElseIf Light = 1 Then If Second = 2 Then Light = 2: Flag = 1 '黃燈變紅燈 Else If Second = 7 Then Light = 0: Flag = 1 '紅燈變綠燈 End If If Flag = 1 Then Set Picture = Image1(Light).Picture End Sub Private Sub Command1_Click() '手動變換燈號 Light = Light + 1 If Light = 3 Then Light = 0 Set Picture = Image1(Light).Picture End Sub -- VB 程式設計 倉木麻衣 PTT 星爺板 行列輸入法 ====================================================== Visual_Basic MaiKuraki Stephen Array -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.222.155.162
fumizuki:沒測試過,希望沒有筆誤 61.222.155.162 05/18