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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date in Holiday array not being found

Status
Not open for further replies.

src2

Technical User
Mar 1, 2001
72
0
0
US
I used to have Crystal Reports version 8.5 and I had several reports for yesterdays work. The reports checked to see if a report date was a work week day and if the date was in a array of manually entered holidays it would go to the previous date and check again until it found a work week day that wasn't a holiday. They all used to work. Now a year or so later I'm getting back to writing some similar reports using Crystal Reports 14. I copied some of my variables and code into my new reports but I'm having problems getting it to work. It appears the code to see if my target date is in the holiday array isn't working and I haven't been able to figure out why. I have made multiple changes such as formatting the dates differently, checking test variables, etc. but I can't get to work. It doesn't recognize July 04, 2011 as a holiday. If someone could help I'd really appreciate it. Here is what I have:.

A Holiday formula with the following in it:

BeforeReadingRecords;
DateVar Array Holidays:=
[
Date (2011, 07, 04),
Date (2011, 09, 05),
Date (2011, 11, 24),
Date (2011, 11, 25),
Date (2011, 12, 23),
Date (2011, 12, 26),
Date (2012, 01, 02),
Date (2012, 04, 06),
Date (2012, 05, 28),
Date (2012, 07, 04),
Date (2012, 09, 03),
Date (2012, 11, 22),
Date (2012, 11, 23),
Date (2012, 12, 24),
Date (2012, 12, 25)
];
0

Another formula called CallDate with the following:

//Before processing - What date records do we want to keep
WhileReadingRecords;

//Define Holiday Array containing dates
//Define Target date as the current date.
//Define 2 number variables Add and Added used to cycle within the array

DateVar Array Holidays;
DateVar Target:= currentdate - 1; // Today is July 6th so to check
NumberVar Add:= -1; // for July 4th I modified the
NumberVar Added:=0; // code to sub -1 to end up with
// July 4th
While Added > Add
Do (target:=target-1;
//Is the target date a workday and not a holiday?
if dayofweek(target) in 2 to 6 and not (target in holidays)
//the target date is a workday and it isn't a holiday so
subtract 1 from Added to exit the loop
then Added:= Added-1
// the target date was either a non-workday or it was a holiday so we want to keep searching
//by keeping added at 0 so we don't exit the loop
else Added:=Added);
Target
 
I can't see anything obviously wrong with your code - and since you've had no replies, it must be something subtle.

I'd suggest changing your method. A test using the 'IN' function, testing dates against a list. You should find details in HELP.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 11.5 with SQL and Windows XP [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top