Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error when trying to run Working Days Between 2 Dates Formula 1

Status
Not open for further replies.

dazum

Technical User
Apr 6, 2011
57
US
I am using CR XI
In the Working Days Between 2 Dates Formula (see below), when I check the formula for errors, in the part of the formula that accounts for a holiday on the line:
For i := 1 to Count (Holidays)
an error occurrs "A field is required here", and the variable Holidays in parenthesis is highlighted.
Has anyone run across this error when trying to use this formula and is there a fix?

This formula is in the report header:
BeforeReadingRecords;
DateTimeVar Holidays := Date(2013,05,27);
0
////Main formula
WhileReadingRecords;
Local DateTimeVar Start := {INTAKE.DECISION_DATE}; // place your Starting Date here
Local DateTimeVar End := {@Activity Date}; // place your Ending Date here
Local NumberVar Weeks;
Local NumberVar Days;
Local Numbervar Hol;
DateTimeVar Holidays;

Weeks:= (Truncate (End - dayofWeek(End) + 1
- (Start - dayofWeek(Start) + 1)) /7 ) * 5;
Days := DayOfWeek(End) - DayOfWeek(Start) + 1 +
(if DayOfWeek(Start) = 1 then -1 else 0) +
(if DayOfWeek(End) = 7 then -1 else 0);
Local NumberVar i;
For i := 1 to Count(Holidays)
do (if DayOfWeek ( Holidays ) in 2 to 6 and
Holidays in start to end then Hol:=Hol+1 );

Weeks + Days - Hol;
 
This line should be

For i = 1 to Count(Holidays)

not

For i := 1 to Count(Holidays)

Ian
 
Ian
I tried your suggestion, but it now it highlights the "=" sign and gives the error "An assignment is expected here".
I tried For i = 1 to Count({@Holiday}) using the formula from the report header, but it gives the same error.

 
Hmmm...

OK go back to the assignment
For i := 1 to Count(Holidays)

But change the datetime var to a datevar array

DateVar Array Holidays := Date(2013,05,27);

Ian
 
Ian
It looks like the syntax of declaring the Holiday array was the problem. In the Report Header formula I changed it to:
BeforeReadingRecords;
DateTimeVar Array Holidays := [
DateTime (2013,05,27), DateTime (2013,07,04)
];
0
In the Main Report formula it now reads:
DateTimeVar Array Holidays;
The formula doesn't error out and it calculates correctly when weekends and holidays are involved in the count.

Thanks for all your assistance!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top