Jump to content

every hour and half hour...


Recommended Posts

if I wanted to do something every half hour, shouldn't I just be able to do this:

If @MIN = 00 Or @MIN = 30 Then
   _wakeup($sound)
EndIf

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

if I wanted to do something every half hour, shouldn't I just be able to do this:

If @MIN = 00 Or @MIN = 30 Then
   _wakeup($sound)
EndIf
Sure, but you'll need to test the condition at least every 60 seconds, probably 55 just to be safe. An AdLib might work nicely if you have other code to run. Otherwise, a strict endless loop would work Something like this:

While1
  If @MIN = 0 OR @MIN = 30 Then
   ;do something
  EndIf
  Sleep(55000)
WEnd

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Or you could get to the first :00 or :30 then Sleep for 60 * 30 * 1000 (30 minutes). I wrote code to sleep until a certain time, it'd be fairly similar. I suppose it depends on how long what you're running will take.

$time = StringSplit(InputBox ("Time to run", "What hour would you like this script to run?  The current time is "& @HOUR & ":" & @MIN & ":" _
     & @SEC,  @HOUR & ":" & @MIN & ":" & @SEC), ":")
;MsgBox(4096, "Done", "Input is " & $time[1] & ":" & $time[2] & ":" & $time[3])
$seconds = ($time[1] - @HOUR) * 3600 + ($time[2] - @MIN ) * 60 + ($time[3] - @SEC )
if ($seconds < 0) Then 
                MsgBox(4096, "Error", "Time already passed!")
    Return(0)
    EndIf
Sleep($seconds * 1000)
MsgBox(4096, "Done", "Woke up at " & @HOUR & ":" & @MIN & ":" & @SEC)

You would just get the current time and recalculate every time...saves on CPU cycles.

Link to comment
Share on other sites

If what you want to do every half-hour takes only a few milliseconds to execute, you could do something like the following:

;Idea:  Look at current time and wait for the next hour or half-hour
;Then once you get in sync, do something, sleep for 30 minutes, do something, sleep 30 minutes...

$offset = @MIN - 30
If $offset < 0 Then
   sleep(-$offset * 60 * 1000)
Else
   sleep((30 - $offset) * 60 * 1000)
EndIf

While 1
   Run("notepad");then thing you do every half-hour would go here
   sleep(1000 * 60 * 30)
WEnd
Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...