Hi All,
This is driving me insane... check it out:
The Scenario:
I have a crystal report that prints from a MySql Server database. The report deals with dates and times and it has 5 groups.
Group 1 groups records by month and year, and so I have a formula like this:
[tt][green]// Group1Formula[/green]
monthIndex := year({theDate}) + month({theDate});[/tt]
Group 2 groups the records by some field in the database, and it goes like this:
[tt][green]// Group2Formula[/green]
if {theField.value} = 1 then
1
else
2;[/tt]
Group 3 groups the records by start and end time (the records have a start and end time) and it looks like this:
[tt][green]// Group3Formula[/green]
{startTime} & " - " & {endTime};[/tt]
And so on with the other two groups.
The Problem:
The problem is the following: I need to know (and print) how many days worth of data I have in every week of every month. To get that, I have an array that keeps a count of the total number of distinct days in each week. Since the number of days in each week is different for every month, I have a formula in the header of Group1 that redims the array so that the number of days in each week are set to 0 for every month. Well, my array is not being reset for some reason, and the total number of days that I get is the total number of days for all the months that I have.
Am I missing something?
Here's the formula that resets the array... it's found in the header of group 1.
[tt][green]// Resetting Formula[/green]
global numbervar array arrActualDaysInWeek;
redim arrActualDaysInWeek[5];
[green]//this isn't really needed but i did it anyways[/green]
arrActualDaysInWeek[1] := 0;
arrActualDaysInWeek[2] := 0;
arrActualDaysInWeek[3] := 0;
arrActualDaysInWeek[4] := 0;
arrActualDaysInWeek[5] := 0;[/tt]
And here's the formula that keeps trak of the number of days in each week. This is found the Details section:
In the code above, WeekOfMonth is a custom function that returns the week number (from 1 to 5) that a given day falls in a month. It's bulletproof so that's not the problem. But, when I print the report, arrDatesInWeek and arrActualDaysInWeek reflect the total unique days for all months in the data. How can this be? I'm resetting these arrays in the resetting formula that's in the footer of group 1 so these values must be reset for every group.
Am I missing something?
Thanks!
JC
_________________________________________________
To get the best response to a question, read faq222-2244.
This is driving me insane... check it out:
The Scenario:
I have a crystal report that prints from a MySql Server database. The report deals with dates and times and it has 5 groups.
Group 1 groups records by month and year, and so I have a formula like this:
[tt][green]// Group1Formula[/green]
monthIndex := year({theDate}) + month({theDate});[/tt]
Group 2 groups the records by some field in the database, and it goes like this:
[tt][green]// Group2Formula[/green]
if {theField.value} = 1 then
1
else
2;[/tt]
Group 3 groups the records by start and end time (the records have a start and end time) and it looks like this:
[tt][green]// Group3Formula[/green]
{startTime} & " - " & {endTime};[/tt]
And so on with the other two groups.
The Problem:
The problem is the following: I need to know (and print) how many days worth of data I have in every week of every month. To get that, I have an array that keeps a count of the total number of distinct days in each week. Since the number of days in each week is different for every month, I have a formula in the header of Group1 that redims the array so that the number of days in each week are set to 0 for every month. Well, my array is not being reset for some reason, and the total number of days that I get is the total number of days for all the months that I have.
Am I missing something?
Here's the formula that resets the array... it's found in the header of group 1.
[tt][green]// Resetting Formula[/green]
global numbervar array arrActualDaysInWeek;
redim arrActualDaysInWeek[5];
[green]//this isn't really needed but i did it anyways[/green]
arrActualDaysInWeek[1] := 0;
arrActualDaysInWeek[2] := 0;
arrActualDaysInWeek[3] := 0;
arrActualDaysInWeek[4] := 0;
arrActualDaysInWeek[5] := 0;[/tt]
And here's the formula that keeps trak of the number of days in each week. This is found the Details section:
Code:
global numbervar totalDays;
global datevar array datesArr;
global numbervar firstDayOfWeek;
global numbervar array arrActualDaysInWeek;
global datevar array arrDatesInWeek1;
global datevar array arrDatesInWeek2;
global datevar array arrDatesInWeek3;
global datevar array arrDatesInWeek4;
global datevar array arrDatesInWeek5;
local numbervar weekIdx;
local numbervar returnVal := 0;
if {template} = 0 then
(
if not (({theDate} in datesArr)) then
(
// check if this date must be counted
if dayofweek({theDate}, firstDayOfWeek) <= {?DaysInWeek} then
(
// total days in the whole month
totalDays := totalDays + 1;
redim preserve datesArr[totalDays];
datesArr[totalDays] := {rundown.rundownDate};
// total days in the week
weekIdx := WeekOfMonth({theDate}, firstDayOfWeek, {?DaysInWeek});
arrActualDaysInWeek[weekIdx] := arrActualDaysInWeek[weekIdx] + 1;
select weekIdx
case 1:
(
redim preserve arrDatesInWeek1[arrActualDaysInWeek[weekIdx]];
arrDatesInWeek1[arrActualDaysInWeek[weekIdx]] := {theDate};
)
case 2:
(
redim preserve arrDatesInWeek2[arrActualDaysInWeek[weekIdx]];
arrDatesInWeek2[arrActualDaysInWeek[weekIdx]] := {theDate};
)
case 3:
(
redim preserve arrDatesInWeek3[arrActualDaysInWeek[weekIdx]];
arrDatesInWeek3[arrActualDaysInWeek[weekIdx]] := {theDate};
)
case 4:
(
redim preserve arrDatesInWeek4[arrActualDaysInWeek[weekIdx]];
arrDatesInWeek4[arrActualDaysInWeek[weekIdx]] := {theDate};
)
case 5:
(
redim preserve arrDatesInWeek5[arrActualDaysInWeek[weekIdx]];
arrDatesInWeek5[arrActualDaysInWeek[weekIdx]] := {theDate};
);
); //if dayofweek({rundown.rundownDate}, firstDayOfWeek) <= {?DaysInWeek})
); //if not (({theDate} in datesArr)) then
); //if {template} = 0 then
In the code above, WeekOfMonth is a custom function that returns the week number (from 1 to 5) that a given day falls in a month. It's bulletproof so that's not the problem. But, when I print the report, arrDatesInWeek and arrActualDaysInWeek reflect the total unique days for all months in the data. How can this be? I'm resetting these arrays in the resetting formula that's in the footer of group 1 so these values must be reset for every group.
Am I missing something?
Thanks!
JC
_________________________________________________
To get the best response to a question, read faq222-2244.