Periodical update - timer

Just starting out? Need help? Post your questions and find answers here.
User avatar
pb-user
User
User
Posts: 10
Joined: Tue Mar 02, 2010 6:36 pm

Periodical update - timer

Post by pb-user »

Hello,

after a lot of tests and search of "Timer" topics I would like to raise my question because of no existing solution. I hope somone can give me a hint :-)

I would like to update a webcam picture at every 15 minutes. First I used timer event, but this is not accurate. Because I would like to update it on e.g. 01:00.00, 01.15.00... The next solution was to put into the EventID-loop a check of the current time (minutes and seconds only) after this check if is e.g. 02:00:00am to perform an action.

Code: Select all

 Time$ = FormatDate("%ii:%ss", Date())
 If Time$="00:00" Or Time$="15:00" Or Time$="30:00" Or Time$="45:00"
   StatusBarText(0, 2, Time$, #PB_StatusBar_Center) ; Statusbar shows last update
endif
The problem is now, if the window is not active or has no focus the check passed the time and nothing happens.

All tips and ideas welcome.
Last edited by pb-user on Tue Jun 07, 2011 8:26 am, edited 1 time in total.
Pb-User

Windows 7 - 64bit - PureBasic 4.51
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Periodical update - timer

Post by blueznl »

Use a combination of the two. Set a timer for every second, and when the timer triggers check if the clock matches the proper time, otherwise just wait for the next timer event.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
pb-user
User
User
Posts: 10
Joined: Tue Mar 02, 2010 6:36 pm

Re: Periodical update - timer

Post by pb-user »

blueznl,

thx for your tip. I will try it.
Pb-User

Windows 7 - 64bit - PureBasic 4.51
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Periodical update - timer

Post by Psychophanta »

Perhaps this could be help you in windows:
http://www.purebasic.fr/english/viewtop ... 12&t=46586
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
pjay
Enthusiast
Enthusiast
Posts: 251
Joined: Thu Mar 30, 2006 11:14 am

Re: Periodical update - timer

Post by pjay »

The code you posted should work fine - if you're using WaitWindowEvent in your main loop, ensure you're also using a timeout value, see the example below (using 15 second intervals).

Code: Select all

OpenWindow(1,4,4,240,320,"",#PB_Window_MinimizeGadget)
ListViewGadget(1,4,4,232,312)

Date_Target = (Date() - (Date() %15)) + 15
SetWindowTitle(1,"Target Time: "+FormatDate("%hh:%ii:%ss",Date_Target))

Repeat
  event = WaitWindowEvent(200)
  If Date() => Date_Target
    Date_Target = Date()+15
    AddGadgetItem(1,-1,"Hit target time @"+ FormatDate("%hh:%ii:%ss",Date()))
    SetWindowTitle(1,"Target Time: "+FormatDate("%hh:%ii:%ss",Date_Target))
  EndIf
Until event = #PB_Event_CloseWindow
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Periodical update - timer

Post by Psychophanta »

That's right pjay,
anyway i just treated to show an elegant way to manage timers under MS windows using just the functions in my code.
Multimedia timers are all purpose timers, not only for window & gadget stuff.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply