Jump to content

making operation once at specific time in loop


Recommended Posts

I have a script with a while loop every 100ms, but I could change the interval in the future.

I want to make some operations only once at a specific time: 11:00:00, 11:40:00 etc.

So I wrote:

$interval = 100
while 1 
if @Hour = 11 and @MIN = 00 And @SEC = 00 then 
    ;make my operation 
EndIf 


if @Hour = 11 and @MIN = 40 And @SEC = 00 then 
    ;make my operation 
EndIf 


Sleep($interval) 
wend

But obviously it fires 10 times.

So, how can I avoid this?

Making a @msec control?

or making a boolean variable changing its state after a second?

Is there a simpler-neater solution?

Link to comment
Share on other sites

I have a script with a while loop every 100ms, but I could change the interval in the future.

I want to make some operations only once at a specific time: 11:00:00, 11:40:00 etc.

So I wrote:

$interval = 100
while 1 
if @Hour = 11 and @MIN = 00 And @SEC = 00 then 
    ;make my operation 
EndIf 


if @Hour = 11 and @MIN = 40 And @SEC = 00 then 
    ;make my operation 
EndIf 


Sleep($interval) 
wend

But obviously it fires 10 times.

So, how can I avoid this?

Making a @msec control?

or making a boolean variable changing its state after a second?

Is there a simpler-neater solution?

It's normal the sleep time is 100 ! ( 10 fire * 100 ms = 1 Second )

Add a sleep ( 1000 ) before ;make my operation ! Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

There are a number of ways, you could add a flag

$bFlag = True
$interval = 100
while 1 
if @Hour = 11 and @MIN = 00 And @SEC = 00 And $bflag = True then
        $bflag = False 
    ;make my operation 
EndIf 
If @SEC <> 00 Then
        $bflag = False
EndIf
Sleep($interval) 
wend

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Thnk you, yes, with boolean.

I changed a bit like this:

$interval = 100
while 1
if @Hour = 13 and @MIN = 20 And @SEC = 00 and $bflag then 
    $bflag = False 
    ;make
EndIf 
if @Hour = 13 and @MIN = 21 And @SEC = 00 and $bflag then
    $bflag = False 
    ;make
EndIf 

If @SEC > 00 Then $bflag = true 
 
Sleep($interval)
Wend

So I use the flag for every timer check 00 sec.

Out of curiosity, which other solution other than @msec?

Edited by frank10
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...