Jump to content

Scheduling Script


Recommended Posts

Below is my code... it logically (in my opinion of course) seems to work. When Sunday rolls around it doesnt excute the code as it is supposed to. If I wait till Sunday then run the script it works fine, but as far as making it just run all the time on a system and it only does its job once on Sunday. I cant seem to get it to work.

Dim $day = @WDAY;Checks the day of the week
Dim $scanned = 0;Makes sure the program only runs once on Sunday's
Dim $delay = 1;Time in hours that it checks the date
$delay = $delay * 60 * 60 * 1000

While 1
   If $day = 1 Then
      If $scanned <> 0 Then

        ;Scheduled code here

      $scanned = 1
      EndIf
   EndIf
   Sleep($delay)
WEnd

Thanks,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

I believe you have a logic error here:

If $scanned <> 0 Then

Don't you want to run the code if it has not been run yet? I think the proper code would be:

While 1
  If $day = 1 Then
     If $scanned = 0 Then; scanned only = 0 if this code has not been run.

      ;Scheduled code here

     $scanned = 1
     EndIf
  EndIf
  Sleep($delay)
WEnd

You said that it ran when it was started on a sunday, but if my logic is correct (which it might not be as it is very late) then it couldn't have.

*** Matt @ MPCS

Link to comment
Share on other sites

  • Developers

You only retrieve the current day one time with Dim $day = @WDAY

You should do this at the "If $day = 1 Then" level like:

If @wday = 1 Then

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

JdeB is right.

I updated your script so you don't have to restart the script every week.

Dim $Sunday = 1
Dim $scanned = 0;Makes sure the program only runs once on Sunday's
Dim $delay = 1;Time in hours that it checks the date
$delay = $delay * 60 * 60 * 1000

While 1
   If @WDAY = $Sunday Then
      If $scanned = 0 Then
         
        ;Scheduled code here
         
         $scanned = 1
      EndIf
   Else
      $scanned = 0
   EndIf
   Sleep($delay)
Wend
Link to comment
Share on other sites

Thank you fellas... The day being checked only once was the problem :) I appreciate it :D.

@Matt The <> 0 thing works, but I had it as 1 at first I was just trying something new ;), but I appreciate the input and it was late when I posted.

Edit: I just looked at my code again.. you are correct the <> thing wouldnt have worked properly. :) Thank Matt.

Thanks again everyone.

JS

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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...