I'm not able to change the code so that when you hit START and then STOP, the program should continue with the value that is on the digit.
Hitting CLEAR is correct : it goes to zero
Hitting START also goes to zero and then start. This should go on ...
- Code: Select all Expand view
- #include "fivewin.ch"
function Main()
local nSecsLapsed
nSecsLapsed := ChronoMeter()
? nSecsLapsed, SECTOTIME( nSecsLapsed, .t. )
return nil
function ChronoMeter()
local oDlg, oSay, oBtnStart, oBtnStop, oTimer, oFont, oBold
local nStartSec, nSecsLapsed := 0
DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-16
DEFINE FONT oBold NAME "Segoe UI" SIZE 0,-32
DEFINE DIALOG oDlg SIZE 500,120 PIXEL TRUEPIXEL FONT oFont
@ 40, 40 BTNBMP oBtnStart PROMPT "START" SIZE 100,40 PIXEL OF oDlg FLAT ;
WHEN nStartSec == nil ;
ACTION ( nStartSec := SECONDS(), oBtnStop:SetFocus() )
@ 40,170 SAY oSay PROMPT { || SECTOTIME( nSecsLapsed, .t. ) } ;
SIZE 160,40 PIXEL OF oDlg FONT oBold CENTER VCENTER UPDATE ;
COLOR CLR_HGREEN, CLR_BLACK
@ 40,360 BTNBMP oBtnStop PROMPT { || If( nStartSec == nil .and. nSecsLapsed > 0, "CLEAR", "STOP" ) } ;
SIZE 100,40 PIXEL OF oDlg FLAT UPDATE ;
WHEN nStartSec != nil .or. nSecsLapsed > 0 ACTION ( ;
If( nStartSec == nil, ;
If( nSecsLapsed > 0, nSecsLapsed := 0, nil ), ;
( nSecsLapsed := SecsLapsed( nStartSec ), nStartSec := nil ) ), ;
oDlg:Update(), oBtnStart:SetFocus() )
oDlg:bInit := <||
DEFINE TIMER oTimer OF oDlg INTERVAL 100 ;
ACTION If( nStartSec == nil,,( nSecsLapsed := SecsLapsed( nStartSec ),oSay:Refresh() ) )
ACTIVATE TIMER oTimer
return nil
>
ACTIVATE DIALOG oDlg CENTERED ;
VALID ( oTimer:End(), .t. )
RELEASE FONT oFont, oBold
return nSecsLapsed
static function SecsLapsed( nStart )
local nLapsed := 0
if nStart != nil
nLapsed := SECONDS() - nStart
if nLapsed < 0
nLapsed += 86400.0
endif
endif
return nLapsed