les,
here's the lot.
code:
if exist ("%systemdrive%\emran.txt")
?"It's there..."
$file = "%systemdrive%\emran.txt"
IF Open(1, $file) = 0
$x = ReadLine(1)
;WHILE @ERROR = 0
? "Line read: [" + $x + "]"
;$x = ReadLine(1)
? "Currentdate: [" + @DATE + "]"
;LOOP
Close (1)
ELSE
BEEP
? "Config file not opened, error code: [" + @ERROR + "]"
ENDIF
?"prefunction"
$DaysBetween=DateMath(@DATE,-7)
? "DaysBetween=" +$DaysBetween
;if over 90 days run
;endif
else
?"not there..."
; $file = "%systemdrive%\emran.txt"
$cr = chr(10) + chr(13)
$ = open(1,$file,5)
if @error = 0
$ = writeline(1,@DATE + $cr)
$ = close(1)
else
?"Unable to create $file ! - [" + @error + "] : " + @serror"
endif
endif
;FUNCTIONS
function DateMath($ExpD1,$ExpD2)
; Author: ScriptLogic Corporation
; if both parameters are dates (yyyy/mm/dd), a positive
; integer indicating the days between the two dates will be returned.
; if the first is a date (yyyy/mm/dd) and the second is an integer
; (number of days), a new date will be returned.
; UDF dependencies: SerialDate, abs
select
case instr($ExpD1,'/') and instr($ExpD2,'/')
; two date passed - return daysbetween integer
$DateMath=serialdate($ExpD1)-serialdate($ExpD2)
if $DateMath<0
$DateMath=$DateMath*-1
endif
case instr($ExpD1,'/') and 1-instr($ExpD2,'/')
; date and a number passed - return date
$ExpD2=0+$ExpD2
$Datemath=serialdate(serialdate($ExpD1)+$ExpD2)
case 1 ; incorrect parameters passed
endselect
endfunction
function SerialDate($ExpD)
; Author: ScriptLogic Corporation
; parameter ($ExpD) must be a date (in the form of yyyy/mm/dd)
; or an integer previously derived by this function.
; if passed a date, it returns an integer.
; If passed an integer, it returns the date.
; Integers can be used for general-purpose math computations on dates
; and then converted back to dates by calling this function again.
; Algorithms were obtained from: http://www.capecod.net/~pbaum/date/date0.htm
dim $z,$h,$a,$b,$c,$y,$m,$d
if instr($ExpD,'/') ; date passed
$y=val(substr($ExpD,1,4))
$m=val(substr($ExpD,6,2))
$d=val(substr($ExpD,9,2))
if $m<3
$m=$m+12
$y=$y-1
endif
; return an integer
$SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
else ; integer passed
$z=0+$ExpD+306 ; cast numeric
$h=100*$z-25
$a=$h/3652425
$b=$a-$a/4
$y=(100*$b+$h)/36525
$c=$b+$z-365*$y-$y/4
$m=(5*$c+456)/153
$d=$c-(153*$m-457)/5
if $m>12
$y=$y+1
$m=$m-12
endif
$m=right('0'+$m,2)
$d=right('0'+$d,2)
; return a string date
$SerialDate=''+$y+'/'+$m+'/'+$d
endif
endfunction