Jump to content

Execute a function at a certain start time and repeat execution for a certain duration


DeDee
 Share

Recommended Posts

Hi

I'm trying to write a program where I need to have a function executed at a certain start time and then repeat execution for a duration. I tried different combinations, but it does not seem to work. Can you share some ideas please?

Link to comment
Share on other sites

  • Moderators

Look at the time macros, such as @HOUR, @MIN, or _nowTime() in the help file.

Or...

Show what you have tried, even if it doesn't work as you would like it to, or explain more about what you're trying to do with this function, so we can assist. Help us help you ;)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Ok. First of all I tried to use AdlibRegister, and I don't understand how this is really working - though it says that checkes every x min/sec...it checks one time for me. Is AdlibRegister not a good option to solve my problem, or am I not using it correcty?

 

#include <Date.au3>  
$StartTime = "18:24"




AdlibRegister("_Check",1000*60)
$duration=30000


While 1;just idle around
Sleep(1000)
WEnd


Func _Check();every minute we check
$CurrentTime = _NowTime(4);the current time
ConsoleWrite("CurrentTime="&$CurrentTime&"---"&"StartTime="&$StartTime)
If ($CurrentTime == $StartTime) Then


  MsgBox(0, "Test", "Execute my function")


$timer = timerinit()
do
;here will execute function


until timerdiff($timer) >= $duration; 




EndIf


AdlibUnRegister();unregister the running function
Exit;and exit
EndFunc
Edited by DeDee
Link to comment
Share on other sites

I found a solution, but I could not make it work with AdlibRegister() and AdlibUnRegister(). If anyone can explain how to use these functions it would help. :)

while 1
        If ($CurrentTime == $startTime) Then
            $timer = timerinit()
            do

               //execute function
                Sleep(1000)

            until timerdiff($timer) >= $duration*1000
            ExitLoop

        Else
            $CurrentTime = _NowTime(4)

        EndIf
    WEnd
Edited by DeDee
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...