FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Timer and using local passed as reference
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Timer and using local passed as reference
Posted: Fri Nov 02, 2012 10:29 PM
To All

I am trying to use local variables to create this elapsed timer. If I make the variables Static .. everything works ( as in this example ), however passing the parameters as Local by reference does not work.

If anyone wonders why I just do not use statics it is because all my modules can be opened multiple times and when I use statics the values 'bleed' between the open modules.

Any Ideas here ?

Rick Lipkin

Code (fw): Select all Collapse
// Testing elapsed time

#include "FiveWin.ch"

Static cTime := "000:00:00:00"
Static nSec,nMin,nHour,nDay

//-------------------
function Main()

Local oDlg, oSay1,oSay2,oSay3,oSay4,oSay5
Local oTmr
*Local nSec,nMin,nHour,nDay

nSec  := 0
nMin  := 0
nHour := 0
nDay  := 0
oTmr  := " "

DEFINE DIALOG oDlg TITLE "Test"

   @ 0.5, 8 Say oSay1 PROMPT "Elapsed Seconds: "+strzero(nSec,2)
   @ 1,   8 Say oSay2 PROMPT "Elapsed Minutes: "+strzero(nMin,2)
   @ 1.5, 8 Say oSay3 PROMPT "Elapsed Hours  : "+strzero(nHour,2)
   @ 2,   8 Say oSay4 PROMPT "Elapsed Days   : "+strzero(nDay,3)
   @ 2.5, 8 Say oSay5 PROMPT "Elapsed Time   : "+cTime


ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT BuildTimer( oDlg,oSay1,oSay2,oSay3,oSay4,oSay5,@oTmr) //;
                       *   @nSec,@nMin,@nHour,@nDay   )

return nil

//-----------------
function BuildTimer( oDlg,oSay1,oSay2,oSay3,oSay4,oSay5,oTmr) //;
*                      nSec,nMin,nHour,nDay,oTmr )

*local oTmr

DEFINE TIMER oTmr OF oDlg ;
      ACTION ( nSec++,;
               If( nSec  >=60,(nMin++,nSec  := 0), ),;
               If( nMin  >=60,(nHour++,nMin := 0), ),;
               If( nHour >=24,(nDay++,nHour := 0), ),;
               cTime := strzero(nDay,3)+":"+strzero(nHour,2)+":"+strzero(nMin,2)+":"+strzero(nSec,2),;
               oSay1:Refresh(),oSay2:ReFresh(),oSay3:ReFresh(),oSay4:ReFresh(),oSay5:ReFresh() );
      INTERVAL 1000

ACTIVATE TIMER oTmr

return nil

// end
Posts: 117
Joined: Tue Jan 03, 2006 06:18 PM
Re: Timer and using local passed as reference
Posted: Sat Nov 03, 2012 12:55 AM
Hi Rick,

Try this :

Code (fw): Select all Collapse
// Testing elapsed time

#include "FiveWin.ch"


function Main()

Local oDlg, oSay1,oSay2,oSay3,oSay4,oSay5

Local nSec,nMin,nHour,nDay
LOCAL cTime := "000:00:00:00"

nSec  := 0
nMin  := 0
nHour := 0
nDay  := 0


DEFINE DIALOG oDlg TITLE "Test"

   @ 0.5, 8 Say oSay1 PROMPT "Elapsed Seconds: "+strzero(nSec,2)
   @ 1,   8 Say oSay2 PROMPT "Elapsed Minutes: "+strzero(nMin,2)
   @ 1.5, 8 Say oSay3 PROMPT "Elapsed Hours  : "+strzero(nHour,2)
   @ 2,   8 Say oSay4 PROMPT "Elapsed Days   : "+strzero(nDay,3)
   @ 2.5, 8 Say oSay5 PROMPT "Elapsed Time   : "+cTime


ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT BuildTimer( oDlg,oSay1,oSay2,oSay3,oSay4,oSay5,@CTIME, ;
                           @nSec,@nMin,@nHour,@nDay   )

return nil

//-----------------
function BuildTimer( oDlg,oSay1,oSay2,oSay3,oSay4,oSay5,CTIME, ;
                       nSec,nMin,nHour,nDay )

LOCAL OTMR                     


DEFINE TIMER oTmr OF oDlg ;
      ACTION ( nSec++,;
               If( nSec  >=60,(nMin++,nSec  := 0), ),;
               If( nMin  >=60,(nHour++,nMin := 0), ),;
               If( nHour >=24,(nDay++,nHour := 0), ),;
               cTime := strzero(nDay,3)+":"+strzero(nHour,2)+":"+strzero(nMin,2)+":"+strzero(nSec,2),;
               oSay1:Refresh(),oSay2:ReFresh(),oSay3:ReFresh(),oSay4:ReFresh(),oSay5:ReFresh() );
      INTERVAL 1000

ACTIVATE TIMER oTmr

return nil


Regards,

kok
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: Timer and using local passed as reference
Posted: Sat Nov 03, 2012 01:37 AM
Hello

it's other way using Hashes

Code (fw): Select all Collapse
// Testing elapsed time

#include "FiveWin.ch"

//-------------------
function Main()

local hDatas := {=>}
local hVar, hObj

*Local nSec,nMin,nHour,nDay

hDatas["var"] = {=>}
hDatas["obj"] = {=>}
hVar = hDatas["var"]
hObj = hDatas["obj"]

hVar["nSec"]  = 0
hVar["nMin"]  = 0
hVar["nHour"] = 0
hVar["nDay"]  = 0
hVar["oTmr"]  = 0
hVar["cTime"] = "000:00:00:00"

DEFINE DIALOG hObj["oDlg"] TITLE "Test"

   @ 0.5, 8 Say hObj["oSay1"] PROMPT "Elapsed Seconds: "+strzero(hVar["nSec"],2)
   @ 1,   8 Say hObj["oSay2"] PROMPT "Elapsed Minutes: "+strzero(hVar["nMin"],2)
   @ 1.5, 8 Say hObj["oSay3"] PROMPT "Elapsed Hours  : "+strzero(hVar["nHour"],2)
   @ 2,   8 Say hObj["oSay4"] PROMPT "Elapsed Days   : "+strzero(hVar["nDay"],3)
   @ 2.5, 8 Say hObj["oSay5"] PROMPT "Elapsed Time   : "+hVar["cTime"]
                
                
ACTIVATE DIALOG hObj["oDlg"] CENTERED ;
      ON INIT BuildTimer( hDatas ) 
                
return nil      
                
//-----------------
function BuildTimer( hDatas )
                
local oTmr     
local hVar := hDatas["var"]
local hObj := hDatas["obj"]
                
DEFINE TIMER oTmr OF hObj["oDlg"] ;
      ACTION ( hVar["nSec"]++,;
               If( hVar["nSec"]  >=60,(hVar["nMin"]++,hVar["nSec"] := 0), ),;
               If( hVar["nMin"]  >=60,(hVar["nHour"]++,hVar["nMin"] := 0), ),;
               If( hVar["nHour"] >=24,(hVar["nDay"]++,hVar["nHour"] := 0), ),;
               hVar["cTime"] := strzero(hVar["nDay"],3)+":"+strzero(hVar["nHour"],2)+":"+strzero(hVar["nMin"],2)+":"+strzero(hVar["nSec"],2),;
               hb_HEval( hObj, {| key, val | If( "oS"$key, val:refresh(), )} ) );
      INTERVAL 1000
                
ACTIVATE TIMER oTmr
                
return nil      
                
// end

Continue the discussion