In a previous thread you gave me an example of how to create a timer with variables using Hashes which worked perfectly.
However, trying to adapt your code to my application, I am running into a problem .. The code appears to work, only the clock elapsed time does not seem to update. Also, The timer needs to be able to stop and start on demand and pick up where it leaves off.
It appears to have something with the Redefine Get oTime line...Here is my code and .rc .. I am sure there is a quick solution and I would appreciate your advice.
Rick Lipkin
// Testing elapsed time
#include "FiveWin.ch"
//-------------------
function Main()
local hDatas := {=>}
local hVar, hObj
Local nClicks
Local oBtnClock,cClockText,oTmr
Local oDlg
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"
oTmr := " "
cClockText := "Start"
nClicks := 1
DEFINE DIALOG oDlg RESOURCE "WORKVIEW" TITLE "Test"
REDEFINE GET hObj["oTime"] var hVar["cTime"] ID 184 of oDlg READONLY
REDEFINE BTNBMP oBtnClock ID 180 PROMPT cClockText ;
CENTER ;
of oDlg ;
ACTION( nClicks++,;
_BuildTimer( oBtnClock,cClockText,@nClicks,hDatas,oDlg,@oTmr))
ACTIVATE DIALOG oDlg CENTERED
return nil
//-----------------
function _BuildTimer( oBtnClock,cClockText,nClicks,hDatas,oDlg,oTmr )
*local oTmr
local hVar := hDatas["var"]
local hObj := hDatas["obj"]
If nClicks = 2 // very first time
cClockText := "Stop"
oBtnClock:cCAPTION := cClockText
oBtnClock:ReFresh()
Else
If IsEven( nCLicks )
* msginfo( "Even")
cClockText := "Start"
oBtnClock:cCAPTION := cClockText
oBtnClock:ReFresh()
cClockText := "Stop"
oBtnClock:cCAPTION := cClockText
oBtnClock:ReFresh()
Else
* msginfo( "Odd")
cClockText := "Stop"
oBtnClock:cCAPTION := cClockText
oBtnClock:ReFresh()
* msginfo( "Stopping timer" )
oTmr:End()
cClockText := "Start"
oBtnClock:cCAPTION := cClockText
oBtnClock:ReFresh()
Return(nil)
Endif
Endif
oBtnClock:ReFresh()
DEFINE TIMER oTmr of 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),;
HEVAL( hObj, {| key, val | If( "oS"$key, val:refresh(), )} ) );
INTERVAL 1000
ACTIVATE TIMER oTmr
return nil
//-------------------------
Func IsEven( nInt )
If empty( nInt )
Return(.f.)
Endif
If ( nInt % 2 == 0 )
Return(.t.)
Endif
Return(.f.)
// endWORKVIEW DIALOG 12, 57, 169, 156
STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU
FONT 6, "MS Sans Serif"
{
CONTROL "Close", 140, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 102, 77, 41, 48
CTEXT "Timer", 168, 5, 34, 27, 11, SS_CENTER | SS_NOPREFIX | WS_GROUP
EDITTEXT 184, 5, 47, 49, 12, ES_AUTOHSCROLL | NOT WS_TABSTOP | WS_BORDER
CONTROL "Timer", 180, "TBtnBmp", 32 | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 59, 36, 35, 30
}