sandiclaus
MIS
Hi,
We are running CR Ver 10.0.0.053 on Windows XP.
I have been struggling with this code for a week now and can't seem to get it right.
My records have a detention start and a detenion end date. Given a parameter report start and end date, I am trying to use arrays to generate an average daily population by Month.
For example: Jan Feb Mar Apr May
117 111 100 94 97
instead I am getting:
519 519 519 519 520
Could someone PLEASE tell me what's wrong with my code?!
I did create a loop to make it error out so I could check my values and the dates and values for my dates, m, d, and x appear to be correct.
WhilePrintingRecords;
Global NumberVar Array MoAvg;
Local NumberVar m;
m := DateDiff('m',{?startdate},{?enddate})+1;
Redim Preserve MoAvg [m];
Local DateVar CheckMonth := {?startdate};
Local DateVar EndMonth := {?enddate};
Local NumberVar i;
Local StringVar Display;
Global NumberVar Array DailyKids;
Local DateVar CheckDate := CheckMonth;
Local DateVar EndDate := DateSerial(Year(CheckDate),Month(CheckDate)+1,1)-1;
Local NumberVar d;
d := EndDate - CheckDate +1;
Redim Preserve DailyKids[d];
Local NumberVar x;
While CheckMonth <= EndMonth
Do
(
i := m - DateDiff('m',CheckMonth, EndMonth);
While (DateSerial(Year(CheckMonth),Month(CheckMonth)+1,1)-1) - CheckDate >= 0
Do
(
x:= d - (EndDate - Checkdate);
if {@DetStart} <= CheckDate
and ({@DetEnd}>= CheckDate or {@DetEnd}=Date(0000,0,0)) then
DailyKids[x] := DailyKids[x]+1;
CheckDate := CheckDate + 1;
EndDate := DateSerial(Year(CheckDate),Month(CheckDate)+1,1)-1
);
MoAvg := Sum(DailyKids)/d;
CheckMonth := CDate(DateAdd ('m',1,CheckMonth))
);
For i := 1 to ubound(MoAvg)
Do
Display := Display & Cstr(MoAvg,0,"") & Chr(9)& Chr(9);
Display
Any help would be greatly appreciated!
Sandi
We are running CR Ver 10.0.0.053 on Windows XP.
I have been struggling with this code for a week now and can't seem to get it right.
My records have a detention start and a detenion end date. Given a parameter report start and end date, I am trying to use arrays to generate an average daily population by Month.
For example: Jan Feb Mar Apr May
117 111 100 94 97
instead I am getting:
519 519 519 519 520
Could someone PLEASE tell me what's wrong with my code?!
I did create a loop to make it error out so I could check my values and the dates and values for my dates, m, d, and x appear to be correct.
WhilePrintingRecords;
Global NumberVar Array MoAvg;
Local NumberVar m;
m := DateDiff('m',{?startdate},{?enddate})+1;
Redim Preserve MoAvg [m];
Local DateVar CheckMonth := {?startdate};
Local DateVar EndMonth := {?enddate};
Local NumberVar i;
Local StringVar Display;
Global NumberVar Array DailyKids;
Local DateVar CheckDate := CheckMonth;
Local DateVar EndDate := DateSerial(Year(CheckDate),Month(CheckDate)+1,1)-1;
Local NumberVar d;
d := EndDate - CheckDate +1;
Redim Preserve DailyKids[d];
Local NumberVar x;
While CheckMonth <= EndMonth
Do
(
i := m - DateDiff('m',CheckMonth, EndMonth);
While (DateSerial(Year(CheckMonth),Month(CheckMonth)+1,1)-1) - CheckDate >= 0
Do
(
x:= d - (EndDate - Checkdate);
if {@DetStart} <= CheckDate
and ({@DetEnd}>= CheckDate or {@DetEnd}=Date(0000,0,0)) then
DailyKids[x] := DailyKids[x]+1;
CheckDate := CheckDate + 1;
EndDate := DateSerial(Year(CheckDate),Month(CheckDate)+1,1)-1
);
MoAvg := Sum(DailyKids)/d;
CheckMonth := CDate(DateAdd ('m',1,CheckMonth))
);
For i := 1 to ubound(MoAvg)
Do
Display := Display & Cstr(MoAvg,0,"") & Chr(9)& Chr(9);
Display
Any help would be greatly appreciated!
Sandi