[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『ストップウォッチの作成』(とら)
ユーザーフォームにて、「開始」、「中断」、「終了」の3つのボタンを配置し、開始ボタンで計測開始、中断で計測ストップ、開始ボタンで中断した時間から計測再開、終了で計測終了となるような動作をさせてたいのですが、
うまくできません。
現在のコードは、下記の通りになりますが、
中断をすると計測は中断されますが、開始を押すとよくわからない時間からスタートされてしまいます。
どうすればよいでしょうか?
timer_tgはグローバル変数です。
Private Sub CommandButton1_Click()※開始ボタンクリック
Dim btTimer As Double
timer_tg = "ON"
If TextBox3 = "" Then
btTimer = timer Else btTimer = TextBox3 End If
Do While timer_tg = "ON"
DoEvents TextBox3 = Format(Int((timer - btTimer) * 100) / 100, "0.00") Loop
End Sub
Private Sub CommandButton2_Click()※中断ボタンクリック
timer_tg = "STOP"
End Sub
< 使用 Excel:Excel2019、使用 OS:Windows10 >
手順を並べていけば、ご自身のコードとの不一致が
見つかると思います。
(tkit) 2020/05/25(月) 14:20
5秒でとめて、5秒後に再開したときのTextBox3 は
「53303、**」でした。
通常は、1、** の1がカウントアップで、**は高速にカウントアップで数字は読み取れません。
Private Sub CommandButton1_Click()
Dim btTimer As Double
timer_tg = "ON"
If TextBox3 = "" Then
btTimer = timer Else btTimer = (timer - st_timer_tg) + CDbl(TextBox3) End If
Do While timer_tg = "ON"
DoEvents TextBox3 = Format(Int((timer - btTimer) * 100) / 100, "0.00") Loop
End Sub
Private Sub CommandButton2_Click()
Dim btTimer As Double
st_timer_tg = Format(Int((timer - btTimer) * 100) / 100, "0.00")
timer_tg = "STOP"
End Sub
(とら) 2020/05/25(月) 14:49
timer関数のヘルプを見て確認してください。 ストップウォッチの経過時間は、timerの初期値(btTime)と現在値の差で求めます。 再開したとき、btTimerの値に、経過時間を入れてもうまくいきません。
Dim timer_tg As String
Private Sub CommandButton1_Click()
Dim btTimer As Double, laptime As Double
timer_tg = "ON" btTimer = Timer
If TextBox3 <> "" Then laptime = CDbl(TextBox3.Text) End If
Do While timer_tg = "ON" DoEvents TextBox3 = Format(Int((Timer - btTimer) * 100) / 100, "0.00") + laptime Loop
End Sub
Private Sub CommandButton2_Click() timer_tg = "STOP" End Sub (てくてく) 2020/05/25(月) 15:10
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.