@Subset Problem

I hoping someone can help? This has got me puzzled? I am basically pickign this information up from a list of public holiday dates. I have the code search the list and if any of the dates there it gives me a total at the end which can then be subtracted from in this case holiday dates.

The code works but it is ignoring the last date on the list. The form with the public holiday dates only has the facility to enter 8 dates.

This is part of the code I am using if I remove one of the 8 dates and only have 7 it works fine? Im kind of stuck now.

Holidays points to the list with the dates on…the total of bank hols is then used to subtract from the total days required.

Holiday1 := @Subset(Holidays;1);

Holiday2 := @Subset(@Subset(Holidays;2);-1);

Holiday3 := @Subset(@Subset(Holidays;3);-1);

Holiday4 := @Subset(@Subset(Holidays;4);-1);

Holiday5 := @Subset(@Subset(Holidays;5);-1);

Holiday6 := @Subset(@Subset(Holidays;6);-1);

Holiday7 := @Subset(@Subset(Holidays;7);-1);

Holiday8 := @Subset(@Subset(Holidays;8);-1);

Hol1 := @TextToTime(Holiday1);

Hol2 := @TextToTime(Holiday2);

Hol3 := @TextToTime(Holiday3);

Hol4 := @TextToTime(Holiday4);

Hol5 := @TextToTime(Holiday5);

Hol6 := @TextToTime(Holiday6);

Hol7 := @TextToTime(Holiday7);

Hol8 := @TextToTime(Holiday8);

BankHols :=

(@If(Hol1 >= From & Hol1 <= To;1;0));

  • (@If(Hol2 >= From & Hol2 <= To;1;0));

  • (@If(Hol3 >= From & Hol3 <= To;1;0));

  • (@If(Hol4 >= From & Hol4 <= To;1;0));

  • (@If(Hol5 >= From & Hol5 <= To;1;0));

  • (@If(Hol6 >= From & Hol6 <= To;1;0));

  • (@If(Hol7 >= From & Hol7 <= To;1;0));

  • (@If(Hol8 >= From & Hol8 <= To;1;0));

Thanks for any help anyone can offer

Mark

Subject: Try a rewrite…

I can’t see anything specifically wrong with the code. But since you are using ND6, you can use an @For loop to rewrite it more cleanly:

===================================

BankHols := 0;

@For(x=1;x<=@Elements(Holidays); x := x + 1;

thisHol := @TextToTime(Holidays[x]);

@If(thisHol >= From & thisHol <= To;BankHols := BankHols + 1; "")

)

====================================

This version also doesn’t limit you to eight holidays, in case the need for more arises.

Subject: RE: Try a rewrite…

I have switched the code and it is still the same, It picks up the first dates, i.e 1st, 2nd and 3rd Jan are all fine. You put in those dates and it recognises all 3. Yet when I put in 25th and 26th Dec (which happen to be the last dates on the list) it only recognises the 25th?

Im puzzled?

Subject: Test Dates?

Can you give us the start/end dates you are testing?

I tested, using the following code and it came up with 8. (Sorry I forgot to add the colon in the first part of the @If statement in the last post.)

================================

Holidays := “01/01/2007” : “01/15/2007” : “02/19/2007” : “05/28/2007” : “07/04/2007” : “09/03/2007” : “11/27/2007” : “12/25/2007”;

From := [01/01/2007];

To := [12/28/2007];

BankHols := 0;

@For(x := 1; x <= @Elements(Holidays); x := x + 1;

thisHol := @TextToTime(Holidays);

@If(thisHol >= From & thisHol <= To; @Set(“BankHols”; BankHols + 1); “”);

@Prompt([OK]; @Text(x) + " element"; @Text(BankHols));

);

BankHols

================================

Subject: RE: Test Dates?

Thank you all for your help,

I ended up just wiping out the whole code and re-did it with your suggestions and it is now working? Im still not sure what has changed but its working? Result

Thanks again

Subject: @Subset Problem

shouldn’t holiday8 be just:

Holiday8 := @Subset(Holidays;-1)

to get the last entry in the Hoildays list?