Jump to content

Timed Functions


Recommended Posts

Background:

I am attempting to create a script which uses times that differ based on outside information in order to run a specific function at that specific time. The outcome will make it so all of the events conclude at the same time but must be started at differing times.

It needs to run the first check against system time, wait till it completes then move on to the next check for system time, perform it's task, then move on, etc. I need 5 iterations of this altogether.

I was able to get the following example in post http://www.autoitscript.com/forum/index.php?showtopic=82731&view=findpost&p=592349 to work but I need it for more than one time to perform 5 different functions. I am only vaugly familiar with While...When loops and have little to no knowledge of Do...Until loops.

Here is what I was thinking might work but obviously didn't:

#include <Date.au3>

$alphaTime = "12:00AM"
$bravoTime = "12:15AM"
$charlieTime = "12:30AM"
$deltaTime = "12:45AM"
$echoTime = "1:00AM"

While 1
    If StringTrimRight($alphaTime,2) = StringStripWS(StringTrimRight(_NowTime(), 6),8) _
        AND StringRight($alphaTime, 2) = StringRight(_NowTime(), 2) Then alpha()
    Do
        ;nothing
    Until StringTrimRight($alphaTime,2) <> StringStripWS(StringTrimRight(_NowTime(), 6),8) ;so it only runs once in that minute
WEnd

;more things to check for the next set of times to run the next function

Func alpha()
    ;do stuff
EndFunc

Func bravo()
    ;do stuff
EndFunc

Func charlie()
    ;do stuff
EndFunc

Func delta()
    ;do stuff
EndFunc

Func echo()
    ;do stuff
EndFunc

Basically I need it to check each time variable against the system clock and just do the function all the while still continuing to check times on the remaining time variables. Any help would be greatly appreciated.

Thanks,

Matt

P.S. I searched the forum but only found the post referenced above.

Link to comment
Share on other sites

I may have figured it out simply by placing If...Then statements inside of a single While...When loop. I'm still testing different times but so far, it's working to pop open a test message for each If...Then statement. I'll post final code when it's complete. Thanks for reading and any possible tips!

Matt

Link to comment
Share on other sites

This is the code and it works great for what I need it to do. Sorry for wasting anyone's time but maybe this can help someone out there also. Not sure why the If...Then statements inside the While...When loop worked this time and not last but maybe it was just dumb luck or overlooking something before. Feel free to "solve" and close this.

Thanks again,

Matt

#include <Date.au3>

$alphaTime = "17:04:00"
$bravoTime = "17:03:45"
$charlieTime = "17:04:45"
$deltaTime = "17:04:15"
$echoTime = "17:04:30"

While 1
    If $alphaTime = _NowTime(5) Then
        _Alpha()
    EndIf

    If $bravoTime = _NowTime(5) Then
        _Bravo()
    EndIf

    If $charlieTime = _NowTime(5) Then
        _Charlie()
    EndIf

    If $deltaTime = _NowTime(5) Then
        _Delta()
    EndIf

    If $echoTime = _NowTime(5) Then
        _Echo()
    EndIf
WEnd

Func _Alpha()
    MsgBox(0, "Alpha", "Test of Alpha")
EndFunc

Func _Bravo()
    MsgBox(0, "Bravo", "Test of Bravo")
EndFunc

Func _Charlie()
    MsgBox(0, "Charlie", "Test of Charlie")
EndFunc

Func _Delta()
    MsgBox(0, "Delta", "Test of Delta")
EndFunc

Func _Echo()
    MsgBox(0, "Echo", "Test of Echo")
EndFunc
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...