我想做個計時器
有個馬錶的功能
按下START後能開始計時
程式碼如下
- Public Class Form1
- Dim st As Boolean 'st 為表示計時器一(碼表)是否啟動的布林變數
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- st = True
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- st = False
- End Sub
- Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
- st = False '關閉碼表計時功能
- TextBox1.Text = 0 '將碼表歸零
- TextBox2.Text = 0
- TextBox3.Text = 0
- TextBox4.Text = 0
- End Sub
- Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
- End
- End Sub
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- If (st = True) Then '若開關是開啟的,則第四欄位(1/100 秒)加一(interval=10ms)
- TextBox4.Text = TextBox4.Text + 1
- TextBox3.Text = TextBox3.Text + TextBox4.Text \ 100 '以下為進位過程
- TextBox4.Text = TextBox4.Text Mod 100
- TextBox2.Text = TextBox2.Text + TextBox3.Text \ 60
- TextBox3.Text = TextBox3.Text Mod 60
- TextBox1.Text = TextBox1.Text + TextBox2.Text \ 60
- TextBox2.Text = TextBox2.Text Mod 60
- End If
- End Sub
- Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
- Label4.Text = Now
- End Sub
- End Class
複製代碼
執行後
我按START
TextBox4.Text = TextBox4.Text + 1
這句會亮起來變成黃色的
然後沒辦法計時
請問為什麼會這樣
要怎麼做修改呢
... |