Sign in to follow this  
Followers 0
Diana (Cda)

[Resolved] Loop for every so many minutes _after_ the hour,

5 posts in this topic

#1 ·  Posted (edited)

Lots of projects on the go these days <g>.

I just came across another situation I don't know how to do. Studied the help files extensively, and have spent last hour and a half dl and looking at and testing clocks/alarms, etc., but haven't found how to do a loop for every so many minutes after the hour.

I know how to loop for every x number of time units, I know how to repeat x number of times, and I even have code to restrict a script running between certain times but I haven't found anything that will back up something at, say, every 57 minutes after the hour (or whatever) so that I'd get backup files at 14h57, 15h57, 16h57, 17h57 ...

What code would we use to do this, pls?

Thanks! :x

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites



Would this work? If @MIN = 57 Then ...


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Maybe

#include <Date.au3>

Dim $HotMin = "17" ; start every xx:17

While 1
    If ( @MIN = $HotMin ) Then
        _DoBackup()
        Sleep (70000) ; wait more than 1 minute to ensure only 1 start within this minute
    EndIf
    Sleep (10000)  ; Look every 10 seconds
WEnd

Func _DoBackup()
    MsgBox(0,'',"It's time for Backup! " & _NowTime())
EndFunc

A-Jay


Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Share this post


Link to post
Share on other sites

Maybe

Long Sleep() is not needed ;-)

#include <Date.au3>

Dim $HotMin = "17" ; start every xx:17
Dim $PrevMin = ""

While 1
    If @MIN = $HotMin And $HotMin <> $PrevMin Then
        _DoBackup()
        $PrevMin = $HotMin
    EndIf
    Sleep (10000)  ; Look every 10 seconds
WEnd

Func _DoBackup()
    MsgBox(0,'',"It's time for Backup! " & _NowTime())
EndFunc

Share this post


Link to post
Share on other sites

Thanks, everyone!

Ajag, for last few days I've been using a script based on your great code. I basically just added an inputbox so user could modify backup time and a tray tooltip so that one could easily see when the backups happen:

If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Back up the file every x minutes after the hour ...","How many minutes past the hour, each hour, should the file be backed up?" & @CRLF & @CRLF & "Note:  Please use number values such as 03, 09, 37, 44, etc." & @CRLF & "           3 means xx:03, 14 would be xx:14, etc." & @CRLF,"3", " ","400","180","350","350")
Select
    Case @Error = 0 ;OK - The string returned is valid
        #include <Date.au3>
        ;------------------
        Dim $HotMin = $sInputBoxAnswer     ; start every x minutes after the hour

        While 1
            #NoTrayIcon     ; AutoIt's icon doesn't show in systray
            TraySetIcon($IconsMine, 77)     ; changes the icon displayed in the systray
            If ( @MIN = $HotMin ) Then
                _DoBackup()
                Sleep (70000) ; wait more than 1 minute to ensure only 1 start within this minute
            EndIf
                Sleep (10000)  ; Look every 10 seconds
                ;-----------------------------------------------------------------  
                TraySetState()
                TraySetToolTip("This script backs up the file every HH:" & $HotMin & ".")
                ;-----------------------------------------------------------------  
        WEnd
    Case @Error = 1 ;The Cancel button was pushed
        Exit     ; finished
    Case @Error = 3 ;The InputBox failed to open
        Exit     ; finished
EndSelect


Func _DoBackup()
    ;======================================================================
    ShellExecute(@ScriptDir & "\" & $BKPfile)
    ;======================================================================
    Beep(5000, 250)
EndFunc

But I came back today to try again to incorporate your changes, Zedna, since reducing time would be ideal.

The modified script is below. I found the TraySetToolTip via googling this week and it's so kewl to get information just with a quick mouse hovering over the script's icon in the systray. With the modified sleep period, the information shows up initially within a few seconds after launching rather than after about 70 seconds. It shows thereafter the same via mouse hover but it's the speed with which is shows up replacing script name with frequency of backup that is due to the reduced sleep period so it seemed like a good change to make.

If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Back up the file every x minutes after the hour ...","How many minutes past the hour, each hour, should the file be backed up?" & @CRLF & @CRLF & "Note:  Please use number values such as 03, 09, 37, 44, etc." & @CRLF & "           3 means xx:03, 14 would be xx:14, etc." & @CRLF,"3", " ","400","180","350","350")
Select
    Case @Error = 0 ;OK - The string returned is valid
        #include <Date.au3>
        ;------------------
        Dim $HotMin = $sInputBoxAnswer     ; start every x minutes after the hour
        Dim $PrevMin = ""

        While 1
            #NoTrayIcon     ; AutoIt's icon doesn't show in systray
            TraySetIcon($IconsMine, 77)     ; changes the icon displayed in the systray
            If @MIN = $HotMin And $HotMin <> $PrevMin Then
                _DoBackup()
                $PrevMin = $HotMin
                Sleep (10000)  ; Look every 10 seconds
            EndIf
                Sleep (10000)  ; Look every 10 seconds
                ;-----------------------------------------------------------------  
                TraySetState()
                TraySetToolTip("This script backs up the file every HH:" & $HotMin & ".")
                ;-----------------------------------------------------------------  
        WEnd
    Case @Error = 1 ;The Cancel button was pushed
        Exit     ; finished
    Case @Error = 3 ;The InputBox failed to open
        Exit     ; finished
EndSelect


Func _DoBackup()
    ;======================================================================
    ShellExecute(@ScriptDir & "\" & $BKPfile)
    ;======================================================================
    Beep(5000, 250)
EndFunc

The hourly back up times change since I boot up or reboot at different times and this script allows me to reset that as needed.

Thanks and cheers! :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0