Karon
(Getting the hang of it)
2017-01-06 08:39 PM
New year and my reports for 2 months ago won't run

we have reports that we run for the period 2 months ago. This was working fine until the new year. I am missing something in the logic.
 Code:
$home = "K:\"
;$home = "c:\Reports\"
$setup = "\\server1\folder1\folder2\setup3.txt"
$source = "\\server2\folder21\folder22\folder23\folder24\"

;open txt file with file and folder names 
IF Open(1, "$setup") = 0
  $drfile = ReadLine(1)
  ELSE
  BEEP
  ? "setup3 file not opened, error code: [" + @ERROR + "]"
  sleep 5
  EXIT
ENDIF

$thismo = @monthno -2
IF $thismo = 0
  $month = "11" 
ELSE
  IF $thismo > 9
    $month = CSTR($thismo)
  ELSE
    $month = "0" + CSTR($thismo)
  ENDIF
ENDIF
$year = IIf(@MONTHNO = 1, @YEAR -1, @YEAR)

;open log file
IF Open(2, "\\server1\folder1\folder2\log$month.txt",5) = 0
  $w = WriteLine( 2 , "rpts3.kix started at " +@DATE + @TIME + Chr(13) + Chr(10) )
  ELSE
  BEEP
  ? "Error opening log file: [" + @ERROR + "]"
  sleep 5
  EXIT
ENDIF

;main program loop
WHILE $readerr = 0
$x = ReadLine(1)
$readerr = @ERROR
$file = SUBSTR($x, 1, INSTR($x, ",")-1)
$x = SUBSTR($x, INSTR($x, ",")+1, LEN($x) - INSTR($x, ","))
$directory = SUBSTR($x, 1, INSTR($x, ",")-1)
$x = SUBSTR($x, INSTR($x, ",")+1, LEN($x) - INSTR($x, ","))
$folder = SUBSTR($x, 1, LEN($x) - INSTR($x, ","))

;MD "$home$directory$folder\$year-$month"

sleep 1

IF Exist("$source$file.pdf")
   IF $folder <> ""
   copy "$source$file.pdf" "$home$directory$folder\$year-$month\$file.pdf"
   ENDIF
ENDIF

LOOP

$w = WriteLine( 2 , "rpts3.kix finished at " +@DATE + @TIME + Chr(13) + Chr(10) )

$ = Close (1)
$ = Close (2)




Last month - 2016-12, I ran the reports for october and they were placed correctly.
My logic for the new year has to off somewhere, because nothing is generating. This is the modified to run for November. The only change I made was to
 Code:
$thismo = @monthno -2
IF $thismo = 0
  $month = "11" ;; last month this was 12 and ran october reports.


Thanks!


Karon
(Getting the hang of it)
2017-01-06 09:00 PM
Re: New year and my reports for 2 months ago won't run

I figured it out. It should read for January:
 Code:
$thismo = @monthno -2
IF $thismo = -1
  $month = "11" ;; to run for november
ELSE
  IF $thismo > 9
    $month = CSTR($thismo)
  ELSE
    $month = "0" + CSTR($thismo)
  ENDIF
ENDIF
$year = IIf(@MONTHNO = 1, @YEAR -1, @YEAR) ;; to run in january


and next month it will read:
 Code:
$thismo = @monthno -2
IF $thismo = 0
  $month = "12" ;; to run for december
ELSE
  IF $thismo > 9
    $month = CSTR($thismo)
  ELSE
    $month = "0" + CSTR($thismo)
  ENDIF
ENDIF
$year = IIf(@MONTHNO = 2, @YEAR -1, @YEAR) ;; to run in February


ChristopheM
(Hey THIS is FUN)
2017-01-07 05:45 PM
Re: New year and my reports for 2 months ago won't run

hello,

i suggest you an other way to prevent multiple tests.
i convert the couple year-month to a integer value, plus or minus the number of months you want and then revert to a couple year-month.
 Code:
dim $num, $olddate

"- current date : " @date ?

$num = SerializeMonth(@date)

"- search 2 months before" ?
$olddate = unserializemonth($num-2)
$year = left($olddate,4)
$month = substr($olddate,6,2)

"2 months before : " $year "/" $month ?
?

"- search 6 months after" ?
$olddate = unserializemonth($num+6)
$year = left($olddate,4)
$month = substr($olddate,6,2)

"6 months after  : " $year "/" $month ?
?
quit


function SerializeMonth( $date )
	; $date in format yyyy/mm

	dim $year, $month
	$year = left($date,4)
	$month = substr($date,6,2)

	$SerializeMonth = val($year)*12 + $month - 1
endfunction

function UnSerializeMonth( $num )
	dim $year, $month
	$month = $num mod 12 + 1
	$year  = $num / 12

	$UnSerializeMonth = right("0000"+CStr($year),4)+"/"+Right("00"+CStr($month),2)
endfunction
Example of result
 Quote:
- current date : 2017/01/07
- search 2 months before
2 months before : 2016/11

- search 6 months after
6 months after : 2017/07


LonkeroAdministrator
(KiX Master Guru)
2017-01-21 04:57 PM
Re: New year and my reports for 2 months ago won't run

Oh so elegant