Sign in to follow this  
Followers 0
13lack13lade

using local time to run script.

5 posts in this topic

#1 ·  Posted (edited)

Hi guys,

I want to have a script which simply creates a copy of the files and saves them to another location, ive got it all work however instead of running it and adding the sleeps in, im wanting to make it so if @HOUR = 9 or (if its 9am, save a copy)

Im wanting to know how autoit works in regards to @Hour it just returns >9 if its anyhere between 9am so my question is if i set the script to if @HOUR = 9 then save, will it ocntinue to save over and over until the time changes to 10? or will it one the script once as soon as it hits 9?
 

Edited by 13lack13lade

Share this post


Link to post
Share on other sites



@HOUR doesn't change until the next hour, so it will be 9 from 9:00:00 am to 9:59:59 am. If you only want it to run once sometime between 9 am and 10 am then you'll have to tell your script to run it once @HOUR = 9, then set a variable as a flag to tell your script you already ran it today. Then reset that variable once @HOUR reaches 10 to set it up for the next day.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I see, do i need to set it up that way with a flag? or if i leave the code as below : will it mean that as soon as the time changes from 8:59 to 9 it should trigger the first if statement and then wait for @HOUR to  change to 10 before running the next?

If @HOUR = 9 then
filecopy($bristrack & $SP, $copy1, 9)
filecopy($bristrack & $AUS,$copy1, 9)
filecopy($asiatrack & $ASIA,$copy1, 9)
filecopy($eurotrack & $EURO,$copy1, 9)
Elseif @HOUR = 10 then
filecopy($bristrack & $SP, $copy2, 9)
filecopy($bristrack & $AUS,$copy2, 9)
filecopy($asiatrack & $ASIA,$copy2, 9)
filecopy($eurotrack & $EURO,$copy2, 9)
Elseif @HOUR = 11 then
filecopy($bristrack & $SP, $copy3, 9)
filecopy($bristrack & $AUS,$copy3, 9)
filecopy($asiatrack & $ASIA,$copy3, 9)
filecopy($eurotrack & $EURO,$copy3, 9)
Elseif @HOUR = 12 then
filecopy($bristrack & $SP, $copy4, 9)
filecopy($bristrack & $AUS,$copy4, 9)
filecopy($asiatrack & $ASIA,$copy4, 9)
filecopy($eurotrack & $EURO,$copy4, 9)
Elseif @HOUR = 13 then
filecopy($bristrack & $SP, $copy5, 9)
filecopy($bristrack & $AUS,$copy5, 9)
filecopy($asiatrack & $ASIA,$copy5, 9)
filecopy($eurotrack & $EURO,$copy5, 9)
Elseif @HOUR = 14 then
filecopy($bristrack & $SP, $copy6, 9)
filecopy($bristrack & $AUS,$copy6, 9)
filecopy($asiatrack & $ASIA,$copy6, 9)
filecopy($eurotrack & $EURO,$copy6, 9)
Elseif @HOUR = 15 then
filecopy($bristrack & $SP, $copy7, 9)
filecopy($bristrack & $AUS,$copy7, 9)
filecopy($asiatrack & $ASIA,$copy7, 9)
filecopy($eurotrack & $EURO,$copy7, 9)
Elseif @HOUR = 16 then
filecopy($bristrack & $SP, $copy8, 9)
filecopy($bristrack & $AUS,$copy8, 9)
filecopy($asiatrack & $ASIA,$copy8, 9)
filecopy($eurotrack & $EURO,$copy8, 9)
EndIf
Edited by 13lack13lade

Share this post


Link to post
Share on other sites

It's not going to wait unless you put it in a loop of some kind. And you will need a flag to tell it to not run each one more than once per day.

Global $Ran9 = False, $Ran10 = False, $Ran11 = False, $Ran12 = False, $Ran12 = False, $Ran13 = False, $Ran14 = False, $Ran15 = False, $Ran16 = False
While 1
    If @HOUR = 9 And Not $Ran9 Then
        FileCopy($bristrack & $SP, $copy1, 9)
        FileCopy($bristrack & $AUS, $copy1, 9)
        FileCopy($asiatrack & $ASIA, $copy1, 9)
        FileCopy($eurotrack & $EURO, $copy1, 9)
        $Ran9 = True
        $Ran16 = False
    ElseIf @HOUR = 10 And Not $Ran10 Then
        FileCopy($bristrack & $SP, $copy2, 9)
        FileCopy($bristrack & $AUS, $copy2, 9)
        FileCopy($asiatrack & $ASIA, $copy2, 9)
        FileCopy($eurotrack & $EURO, $copy2, 9)
        $Ran9 = False
        $Ran10 = True
    ElseIf @HOUR = 11 And Not $Ran11 Then
        FileCopy($bristrack & $SP, $copy3, 9)
        FileCopy($bristrack & $AUS, $copy3, 9)
        FileCopy($asiatrack & $ASIA, $copy3, 9)
        FileCopy($eurotrack & $EURO, $copy3, 9)
        $Ran10 = False
        $Ran11 = True
    ElseIf @HOUR = 12 And Not $Ran12 Then
        FileCopy($bristrack & $SP, $copy4, 9)
        FileCopy($bristrack & $AUS, $copy4, 9)
        FileCopy($asiatrack & $ASIA, $copy4, 9)
        FileCopy($eurotrack & $EURO, $copy4, 9)
        $Ran11 = False
        $Ran12 = True
    ElseIf @HOUR = 13 And Not $Ran13 Then
        FileCopy($bristrack & $SP, $copy5, 9)
        FileCopy($bristrack & $AUS, $copy5, 9)
        FileCopy($asiatrack & $ASIA, $copy5, 9)
        FileCopy($eurotrack & $EURO, $copy5, 9)
        $Ran12 = False
        $Ran13 = True
    ElseIf @HOUR = 14 And Not $Ran14 Then
        FileCopy($bristrack & $SP, $copy6, 9)
        FileCopy($bristrack & $AUS, $copy6, 9)
        FileCopy($asiatrack & $ASIA, $copy6, 9)
        FileCopy($eurotrack & $EURO, $copy6, 9)
        $Ran13 = False
        $Ran14 = True
    ElseIf @HOUR = 15 And Not $Ran15 Then
        FileCopy($bristrack & $SP, $copy7, 9)
        FileCopy($bristrack & $AUS, $copy7, 9)
        FileCopy($asiatrack & $ASIA, $copy7, 9)
        FileCopy($eurotrack & $EURO, $copy7, 9)
        $Ran14 = False
        $Ran15 = True
    ElseIf @HOUR = 16 And Not $Ran16 Then
        FileCopy($bristrack & $SP, $copy8, 9)
        FileCopy($bristrack & $AUS, $copy8, 9)
        FileCopy($asiatrack & $ASIA, $copy8, 9)
        FileCopy($eurotrack & $EURO, $copy8, 9)
        $Ran15 = False
        $Ran16 = True
    EndIf
    Sleep(100)
WEnd

This will run each section only when the hour is correct and it hasn't run already. The flags are the $Ran# variables, and they are set to true when you run that section, and are reset to False when you run the next section. It will keep looping until you kill the script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

thanks brewman for explaining that to me and i can easily understand how it works looking at your script.

greatly appreciated as always

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