FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Add pauze function to Chronometer
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Add pauze function to Chronometer
Posted: Tue Mar 07, 2023 10:54 PM
Mr. Rao posted a chronometer on the forum :

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 (fw): Select all Collapse
#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
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Add pauze function to Chronometer
Posted: Wed Mar 08, 2023 10:05 AM
Change this:
Code (fw): Select all Collapse
ACTION ( nStartSec := SECONDS(), oBtnStop:SetFocus() )
with this:
Code (fw): Select all Collapse
ACTION ( nStartSec := SECONDS() - nSecsLapsed, oBtnStop:SetFocus() )

Continue the discussion