I've written a stopwatch with MS. It can run, but can't be stopped!!
Here's the code. who can show me what's wrong??
Thanks!
Let>APP_TITLE=Aleu's StopWatch
OnEvent>KEY_DOWN,VK83,0,Start
OnEvent>KEY_DOWN,VK80,0,Pause
OnEvent>KEY_DOWN,VK90,0,Zero
OnEvent>KEY_DOWN,VK81,0,Quit
Dialog>Dialog1
Caption=Aleu's StopWatch
Top=540
Left=810
Width=208
Height=100
Button=Start/Pause,6,32,70,26,4
Button=Zero,80,32,56,26,5
Button=Quit,139,32,56,26,6
Default=Start
Edit=Edit1,6,6,186,0
EndDialog>Dialog1
show>Dialog1
Label>CMain
Let>hh=0
Let>mm=0
Let>ss=0
Let>ms=0
Label>ActionLoop
GetDialogAction>Dialog1,r
if>r=4,Start
if>r=5,Zero
if>r=6,Quit
if>r=2,Quit
Wait>0.1
Goto>ActionLoop
Label>Quit
SRT>Start
Label>Start
Let>Dialog1.Edit1=%hh% Hour: %mm% Min: %ss% Sec: %ms% MS
let>ms=ms+16
ResetDialogAction>Dialog1
wait>0.005
wait>0.005
//PushButton>Aleu's StopWatch,Start
If>msssms=0
let>ss=ss+1
Goto>Start
Endif
If>mmms=0
let>ss=0
let>mm=mm+1
Goto>Start
Endif
If>hhms=0
let>ss=0
let>mm=0
let>hh=hh+1
Goto>Start
Endif
End>Start
SRT>pause
ResetDialogAction>Dialog1
Goto>ActionLoop
END>pause
SRT>Zero
Let>Dialog1.Edit1=0 Hour: 0 Min: 0 Sec: 0 MS
ResetDialogAction>Dialog1
Goto>CMain
END>Zero
Stopwatch code
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
When you click start you jump out of the dialog loop to a new loop - your timer loop. The dialog loop determines when a button is clicked but once you cick start you are not in it anymore.
Either a) handle the timer in the main dialog loop, b) check the dialog action for the stop/quit button status in the timer loop, or c) easier - use onevent to handle dialog events.
Either a) handle the timer in the main dialog loop, b) check the dialog action for the stop/quit button status in the timer loop, or c) easier - use onevent to handle dialog events.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
further questions
Thank you for the idea first. I've tried the first two, now the stopwatch can be stopped, but--
It can't be stopped immediately after I push the button! The button needs to be clicked several times before it takes effect.
I think it's due to the 0.01s loop interval---MS can't get the mouse click action within that period. Am I right?
If so, dialogue examples in help file are also not immediate reponses.
Besides, When I clicked the dialogue caption (not released), the timer paused till mouse released. Can this be avoided?
It can't be stopped immediately after I push the button! The button needs to be clicked several times before it takes effect.
I think it's due to the 0.01s loop interval---MS can't get the mouse click action within that period. Am I right?
If so, dialogue examples in help file are also not immediate reponses.
Besides, When I clicked the dialogue caption (not released), the timer paused till mouse released. Can this be avoided?
Ok now
Well, the stopwatch can work now.
Thank mtettmar.
I need one more help to make the stopwatch better------
When it paused, I want to change the "start" button to "Continue", but the code seems not work (Line 63).
Let>hh=0
Let>mm=0
Let>ss=0
Let>ms=0
Let>B1=Start
Let>B2=Pause/Zero
Let>B3=Quit
Dialog>Dialog1
Caption=Aleu's StopWatch
Top=540
Left=810
Width=208
Height=100
Button=B1,6,32,56,26,4
Button=B2,66,32,70,26,5
Button=B3,139,32,56,26,6
Default=B1
Edit=Edit1,6,6,186,0
EndDialog>Dialog1
show>Dialog1
Label>OpenDialogue
GetDialogAction>Dialog1,r
If>r=2,Quit
If>r=6,Quit
If>r=5,Zero
If>r=4,StartTiming
Wait>0.1
If>r=0,OpenDialogue
Label>StartTiming
GetDialogAction>Dialog1,r
If>r=2,Quit
If>r=6,Quit
If>r=5,Pause
If>{(%r%=0) or (%r%=4)}
Let>Dialog1.Edit1=%hh% HH: %mm% MM: %ss% SS: %ms% MS
ResetDialogAction>Dialog1
Gosub>Timer
Wait>0.01
Goto>StartTiming
Endif
Label>Quit
SRT>Quit
Goto>Quit
End>Quit
SRT>Zero
Let>hh=0
Let>mm=0
Let>ss=0
Let>ms=0
Let>Dialog1.Edit1=%hh% HH: %mm% MM: %ss% SS: %ms% MS
ResetDialogAction>Dialog1
Wait>0.01
Goto>OpenDialogue
End>Zero
SRT>Pause
Let>Dialog1.Edit1=Paused! %hh% HH: %mm% MM: %ss% SS: %ms% MS
If>B1=Start
Let>B1=Continue
Endif
ResetDialogAction>Dialog1
Wait>0.01
Goto>OpenDialogue
End>Pause
SRT>Timer
Let>ms=ms+16
If>ms>999
Let>ms=0
Let>ss=ss+1
If>ss>59
Let>ss=0
Let>mm=mm+1
If>mm>59
Let>mm=0
Let>hh=hh+1
If>hh>12,OpenDialogue
Endif
Endif
Endif
Endif
End>Timer
Thank mtettmar.
I need one more help to make the stopwatch better------
When it paused, I want to change the "start" button to "Continue", but the code seems not work (Line 63).
Let>hh=0
Let>mm=0
Let>ss=0
Let>ms=0
Let>B1=Start
Let>B2=Pause/Zero
Let>B3=Quit
Dialog>Dialog1
Caption=Aleu's StopWatch
Top=540
Left=810
Width=208
Height=100
Button=B1,6,32,56,26,4
Button=B2,66,32,70,26,5
Button=B3,139,32,56,26,6
Default=B1
Edit=Edit1,6,6,186,0
EndDialog>Dialog1
show>Dialog1
Label>OpenDialogue
GetDialogAction>Dialog1,r
If>r=2,Quit
If>r=6,Quit
If>r=5,Zero
If>r=4,StartTiming
Wait>0.1
If>r=0,OpenDialogue
Label>StartTiming
GetDialogAction>Dialog1,r
If>r=2,Quit
If>r=6,Quit
If>r=5,Pause
If>{(%r%=0) or (%r%=4)}
Let>Dialog1.Edit1=%hh% HH: %mm% MM: %ss% SS: %ms% MS
ResetDialogAction>Dialog1
Gosub>Timer
Wait>0.01
Goto>StartTiming
Endif
Label>Quit
SRT>Quit
Goto>Quit
End>Quit
SRT>Zero
Let>hh=0
Let>mm=0
Let>ss=0
Let>ms=0
Let>Dialog1.Edit1=%hh% HH: %mm% MM: %ss% SS: %ms% MS
ResetDialogAction>Dialog1
Wait>0.01
Goto>OpenDialogue
End>Zero
SRT>Pause
Let>Dialog1.Edit1=Paused! %hh% HH: %mm% MM: %ss% SS: %ms% MS
If>B1=Start
Let>B1=Continue
Endif
ResetDialogAction>Dialog1
Wait>0.01
Goto>OpenDialogue
End>Pause
SRT>Timer
Let>ms=ms+16
If>ms>999
Let>ms=0
Let>ss=ss+1
If>ss>59
Let>ss=0
Let>mm=mm+1
If>mm>59
Let>mm=0
Let>hh=hh+1
If>hh>12,OpenDialogue
Endif
Endif
Endif
Endif
End>Timer
B1, B2, B3 only have meaning when the dialog block is read and the dialog is defined. After that the names of the buttons are dialog1.msbutton0, dialog1.msbutton1 and dialog1.msbutton2.
Rewrite the lines like this:
SRT>Pause
Let>Dialog1.Edit1=Paused! %hh% HH: %mm% MM: %ss% SS: %ms% MS
If>dialog1.msbutton0=Start
Let>dialog1.msbutton0=Continue
Endif
ResetDialogAction>Dialog1
Wait>0.01
Goto>OpenDialogue
End>Pause
Rewrite the lines like this:
SRT>Pause
Let>Dialog1.Edit1=Paused! %hh% HH: %mm% MM: %ss% SS: %ms% MS
If>dialog1.msbutton0=Start
Let>dialog1.msbutton0=Continue
Endif
ResetDialogAction>Dialog1
Wait>0.01
Goto>OpenDialogue
End>Pause