- 帖子
- 38
- 主題
- 14
- 精華
- 0
- 積分
- 58
- 點名
- 0
- 作業系統
- win xp
- 軟體版本
- office 2007
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2013-5-22
- 最後登錄
- 2020-3-9
|
啟動 緊急 停止 三個按鈕 如何設定 啟動按鈕有按是綠色 沒有按是灰色
緊急按鈕 和停止按紐 有按是紅色 沒有按是灰色
Option Explicit
Dim TimerEnable As Boolean
Dim TimerStop As Boolean
Dim iValue As Integer
' 啟動
Private Sub CommandButton5_Click()
TimerEnable = True
iValue = 0
WaitFor 1 '每秒計數一次
End Sub
' 緊急
Private Sub CommandButton1_Click()
TimerEnable = False
End Sub
' 停止
Private Sub CommandButton2_Click()
TimerStop = True
End Sub
Public Sub WaitFor(Sec As Long)
Dim t0 As Long
Dim DnCnt As Boolean
Do
t0 = Timer
While Timer - t0 < Sec
DoEvents
Wend
If Not DnCnt Then
iValue = iValue + 1
If iValue >= 10 Then
DnCnt = True
End If
Sheets(1).Range("a1").Value = iValue
Else
iValue = iValue - 1
If iValue <= 1 Then
DnCnt = False
If TimerStop Then
TimerStop = False
TimerEnable = False
Exit Do
End If
End If
Sheets(1).Range("a1").Value = iValue
End If
If Not TimerEnable Then Exit Do
Loop
Sheets(1).Range("a1").Value = iValue
End Sub |
|