Run a function at a certain time of day

Post

Posted
Rating:
#1 (In Topic #1161)
Avatar
Regular
sarpomira is in the usergroup ‘Regular’
Hi All,

I'm struggling a bit with this one.
Assume I have a subroutine called "run_analysis()"

Whats the syntax to call this routine every day at 1:30 PM ?

Bonus question:  :lol:
Whats the syntax to call this routine every day at 1:30 PM … on weekdays only ?

thanks for any help
cheers
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
Here is my possible solution. A timer is setup to trigger every minute. It checks to see if today's date is a weekday and if it is then it checks to see if the time is 13:30 and if so runs the required routine.

Code (gambas)

  1. Timer1 As Timer
  2.  
  3. Public Sub Form_Open()
  4.  
  5.   With Timer1 = New Timer As "Timer1"
  6.     .Delay = 60000 ''Delay of 1 min
  7.     .Trigger
  8.     .Start
  9.  
  10.  
  11. Public Sub Timer1_Timer()
  12.  
  13.   If WeekDay(Date(Now)) > 0 And WeekDay(Date(Now)) < 6 Then     '' 0 is Sunday, 7 = Saturday
  14.     If Format(Time(Now), "h:nn") = "13:30" Then run_analysis    '' Is it 1:30PM, if so run the routine
  15.  
  16.  
  17. Public Sub run_analysis()
  18.  
  19.   ''Do important stuff!
  20.    
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
sarpomira is in the usergroup ‘Regular’
To clarify the logic….
When the [START] button is clicked, the code in the button event  is an endless loop which monitors stuff (say… greenhouse environment).
Within the loop is a the "time of day" snippet which calls a subroutine to save some data to a file every day at 1:30 pm.

Thanks gentlemen, I think this is what I was looking for…

 

Code (gambas)

  1.  If WeekDay(Date(Now)) > 0 And WeekDay(Date(Now)) < 6 Then     '' 0 is Sunday, 7 = Saturday
  2.     If Format(Time(Now), "h:nn") = "13:30" Then run_analysis    '' Is it 1:30PM, if so run the routine

Cheers
Online now: No Back to the top
1 guest and 0 members have just viewed this.