Page 1 of 1

Periodical update - timer

Posted: Tue Jun 07, 2011 7:23 am
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.

Re: Periodical update - timer

Posted: Tue Jun 07, 2011 8:12 am
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.

Re: Periodical update - timer

Posted: Tue Jun 07, 2011 8:29 am
by pb-user
blueznl,

thx for your tip. I will try it.

Re: Periodical update - timer

Posted: Wed Jun 08, 2011 4:50 pm
by Psychophanta
Perhaps this could be help you in windows:
http://www.purebasic.fr/english/viewtop ... 12&t=46586

Re: Periodical update - timer

Posted: Wed Jun 08, 2011 7:59 pm
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

Re: Periodical update - timer

Posted: Wed Jun 08, 2011 8:38 pm
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.