Jump to content

still struggling


t0ddie
 Share

Recommended Posts

im having difficulty with how to apply the time macros to serve my purposes.

i want to simply run a script, and the very first time its ran, it should do something.

like.... msgbox(0,"test","this is the first time i have ran")

then it should do nothing every time it has run, unless a week or more time has passed.. then it should be like

msgbox(0,"test","it has been over a week, we meet again")

but then..... it should do nothing every time you run it.... until ANOTHER week has passed...

you know, do something once right away,

then once per week,

but only do these things if the script is run

not schedule them.

any help? thanks!

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

Local $day, $test
$Day = 1;Put there the day of the week beetween 1 to 7

IF @WDAY = 1 Then
   $Test = FileReadLine(@scriptdir & '\done')
   If @error or $test <> @YDAY & '-' & @YEAR Then
      FileDelete(@scriptdir & '\done')
      FileWriteLine(@scriptdir & '\done', @YDAY & '-' & @YEAR)
      
      
      MsgBox(0,'','Hello, today is the day of the week')
   EndIf
EndIf

Link to comment
Share on other sites

yes but.. wont that only do the desired results if they start that script on that day?

i want it so that if a week or more has passed, it will do it again no matter what day it is, when they start the script. then... reset the timer.

wait until another week has passed, then if they run the script, and it hasent been a week, do nothing. if it has been a week OR MORE... then do something.

:lmao:

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

If Not FileExists(@ScriptDir & '\check') Then
   FileWriteLine(@ScriptDir & '\check', @YEAR & '|' & @YDAY)
   
   MsgBox(0, '', 'First time, eh?')
Else
   $aLine = StringSplit(FileReadLine(@ScriptDir & '\check'), '|')
   If Not @error Then
      $aLine[1] = Int($aLine[1])
      $aLine[2] = Int($aLine[2])
      
      Select
         Case $aLine[1] = @YEAR And @YDAY - $aLine[2] >= 7
            $bGo = 1
         Case $aLine[1] = @YEAR-1 And @YDAY + _NDays(@YEAR-1) - $aLine[2] >= 7
            $bGo = 1
         Case @YEAR - $aLine[1] > 1
            $bGo = 1
         Case Else
            $bGo = 0
      EndSelect
      If $bGo = 1 Then
         FileDelete(@ScriptDir & '\check')
         FileWriteLine(@ScriptDir & '\check', @YEAR & '|' & @YDAY)
         
         MsgBox(0, '', 'Ahh, a week is passed...')
      EndIf
   Else
      FileDelete(@ScriptDir & '\check')
      MsgBox(0, '', 'Check file messed up, deleting it and leaving.')
   EndIf
EndIf

Func _NDays($iYear)
   Local $iDays
   Select
      Case Mod($iYear,100) = 0 And Mod($iYear,400) <> 0
         $iDays = 365
      Case Mod($iYeas,4) = 0
         $iDays = 366
      Case Else
         $iDays = 365
   EndSelect
   
   Return $iDays
EndFunc

Edit: This shoud be ok.

Edited by ezzetabi
Link to comment
Share on other sites

Way too much code, ezzetabi. This should be like 10 lines or less.

Things to do:

  • Use Date.au3.
  • On start, read from an INI file which should be the date last ran.
  • If no date found, assume first run, otherwise, compare the dates with _DateDiff() and if the number of days is greater than what you specify, then do your stuff.
  • Before closing, write the current date to the INI file.
Very simple.
Link to comment
Share on other sites

Nothing. I just think Autoit shoud have its macro for having an absolute time.

Just like using time(NULL) in C (from time.h). Maybe @AbsSeconds ?

It would make all this kind of date related problems solveable with nothing more than a difference.

Edited by ezzetabi
Link to comment
Share on other sites

Nothing. I just think Autoit shoud have its macro for having an absolute time.

Just like using time(NULL) in C (from time.h). Maybe @AbsSeconds ?

It would make all this kind of date related problems solveable with nothing more than a difference.

<{POST_SNAPBACK}>

Maybe, maybe not. However, at any rate, there is a working solution in the form of Date.au3 which offers everything I've need so far for date/time work and I've done a lot of stuff with date/time.

So what does it matter how something is done as long as its done? Functions should be thought of as a black box, you put in what it expects, it gives you what you expect. How it does it should be irrelevant.

Edit: Here's the code, 10 lines exactly.

#include <Date.au3>

$today = _NowCalcDate()
$previous = IniRead("MyIni.ini", "Date", "Date", "NOTRUN")
If $previous = "NOTRUN" Then 
    MsgBox(4096, "", "First Run")
ElseIf _DateDiff("d", $previous, $today) >= 7 Then
    MsgBox(4096, "", "Week has passed")
EndIf
IniWrite("MyIni.ini", "Date", "Date", $today)

Even if there was a C-style time() function, you wouldn't be able to reduce that. You still have to:

  • Get today's time.
  • Get the previous run time.
  • Compare the times.
  • Save today's time for future retrieval.
The only thing that would be "eliminated" would be "#include <Date.au3>", however, it wouldn't truly be gone, either all the code would be internal to AutoIt, or perhaps not, perhaps there wouldn't be any Diff-type function, so you'd have to write your own or use a standard version.

Note: This code requies a recent beta to run as I don't think Date.au3 had the functions I'm using prior to a couple months ago.

Edited by Valik
Link to comment
Share on other sites

Maybe I am wrong about preprocessor directives, but #include does not include the whole file called?

The only point of my post was that it is not true that is less code. I have nothing against your solution.

Btw, shoud not be:

#include <Date.au3>

$today = _NowCalcDate()
$previous = IniRead("MyIni.ini", "Date", "Date", "NOTRUN")

If $previous = "NOTRUN" Then 
    IniWrite("MyIni.ini", "Date", "Date", $today)
    MsgBox(4096, "", "First Run")
ElseIf _DateDiff("d", $previous, $today) >= 7 Then
    IniWrite("MyIni.ini", "Date", "Date", $today)
    MsgBox(4096, "", "Week has passed")
EndIf

Instead of:

#include <Date.au3>

$today = _NowCalcDate()
$previous = IniRead("MyIni.ini", "Date", "Date", "NOTRUN")
If $previous = "NOTRUN" Then 
    MsgBox(4096, "", "First Run")
ElseIf _DateDiff("d", $previous, $today) >= 7 Then
    MsgBox(4096, "", "Week has passed")
EndIf
IniWrite("MyIni.ini", "Date", "Date", $today)

Or you'll have to wait a week without calling the script... No?

Edited by ezzetabi
Link to comment
Share on other sites

Don't be so technical.

When counting the number of lines of code in a C/C++ application, would you count the number of lines from the C/C++ standard libraries? If you use std::vector in your C++ app, do you count all 1700+ lines as part of your code?

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