FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Timer with Menu / button options
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Timer with Menu / button options
Posted: Mon Jun 25, 2012 09:53 PM

I've been looking at various threads here about timers. I haven't seen what I want to do, so maybe somebody has some ideas on this.

I have a "utility application" that does a series of tasks every six hours. The rest of the time it sleeps. It runs on a server and is usually not in view.

What I want to do is create a window with menu items that let me "force an update", "view the log", and "exit". In addition, I want to have it run the subroutine every six hours.

The issue is the menu items must be clickable while the timer is running, and allow those functions to be called.

Has anyone worked with this who might know of some sample code ?

Thanks

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Timer with Menu / button options
Posted: Tue Jun 26, 2012 01:49 AM
Tim,

This example counts a minute. If you replace 60 with ( 60 * 60 * 6 ), then it will count six hours:

Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd TITLE "Counting minutes"

   ACTIVATE WINDOW oWnd ;
      ON INIT BuildTimer()

return nil

function BuildTimer()

   local oTmr, nStart := Seconds()

   DEFINE TIMER oTmr INTERVAL 1000 ;
      ACTION If( Seconds() - nStart > 60, ( nStart := Seconds(), MsgInfo( "a minute" ) ), )

   ACTIVATE TIMER oTmr

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Timer with Menu / button options
Posted: Tue Jun 26, 2012 04:13 PM
I did figure that out yesterday ... at first I thought the number was in seconds, but interval measures thousands of a second according to the documentation.

Originally I used 21600 for 6 hours, but it was running the function called every 21.6 seconds !

From the online doc:
<nInterval> Defines the timer interval in thousandths of seconds.


Can you please confirm this ?
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Timer with Menu / button options
Posted: Tue Jun 26, 2012 07:02 PM
Tim,

Yes, milliseconds:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644906(v=vs.85).aspx

thats why I used 1000 when creating the timer, to fire the action every second. It would be better a wider interval so the app manages less events
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Timer with Menu / button options
Posted: Tue Jun 26, 2012 07:11 PM

Got It ! I set the interval to the total time ... will change it to your example. Thanks

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Timer with Menu / button options
Posted: Wed Jun 27, 2012 07:05 PM

OK ... I worked this out but for anyone else who has an issue.

IF your timer will go for longer than the current day, do not use Seconds( ). By default it resets to 0 at midnight.

Instead I used ElapTime( ) which will take into account when a day changes, and keep right on working !

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit

Continue the discussion