Page 1 of 1 1
Topic Options
#212192 - 2017-01-06 08:39 PM New year and my reports for 2 months ago won't run
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
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!


Edited by Karon (2017-01-06 08:42 PM)

Top
#212193 - 2017-01-06 09:00 PM Re: New year and my reports for 2 months ago won't run [Re: Karon]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
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

Top
#212194 - 2017-01-07 05:45 PM Re: New year and my reports for 2 months ago won't run [Re: Karon]
ChristopheM Offline
Hey THIS is FUN
*****

Registered: 2002-05-13
Posts: 309
Loc: STRASBOURG, France
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
_________________________
Christophe

Top
#212236 - 2017-01-21 04:57 PM Re: New year and my reports for 2 months ago won't run [Re: ChristopheM]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Oh so elegant
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.052 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org