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

A subscript must be between 1 and the size of the array

Status
Not open for further replies.

Hacim

Technical User
Sep 5, 2002
63
US
I am trying insert a formula designed from another report which calculates age of work orders while excluding holidays, weekends etc. I don't have a clue what this error is referencing.

WhileReadingRecords;
DateVar Array Holidays;
DateVar Start := if {WO.WOTYPE}='PM' THEN Date({WO.SCHEDSTARTDATE}) ELSE Date({WO.REQUESTDATE});
DateVar End := if isnull({WO.COMPLETIONDATE}) then Currentdate else Date({WO.COMPLETIONDATE});
NumberVar Weeks;
NumberVar Days;
NumberVar Hol:= 0;
//Figure the number of Calendar "Rows" involved and count 5 days for each:
Weeks:= (Truncate (End - dayofWeek(End) + 1 -
(Start - dayofWeek(Start) + 1)) /7 ) * 5; //Adjust the first and last weeks based on when in the week you start and end
Days := DayOfWeek(End) - DayOfWeek(Start) + 1
+ (if DayOfWeek(Start) = 1 then -1 else 0) //adjust for starting on a Sunday:
+ (if DayOfWeek(End) = 7 then -1 else 0); //adjust for ending on a Saturday:

//Adjust for Holidays in the period between the start and end dates:

Local NumberVar i;
For i := 1 to Count(Holidays)

Do ( if Holidays in start to end
then Hol:=Hol+1
else Hol:=Hol);

//Assemble the adjusted work days
Weeks + Days - Hol
 
I think that in "For i := 1 to Count(Holidays)", Holidays contains nothing, hence the error.

Is it defined in another formula? If not, you need the holidays defined somewhere.

I think that there's a FAQ here or on Ken Hamadys site regarding this method for determining weekends and holidays.

I suggest that you build a periods table that defines has attributes defining business days, holidays and weekends, which is a standard model in Data Warehouses and eliminates proprietary coding within reports, programs, etc. The you can join it to your query and select only days that are business days.

-k
 
Hi Hacim,

SynapseVampire's right in that you're getting this problem because the count of your Holidays array is very likely zero.

The UBound function verifies the amount of values in an array. Use this function to avoid getting the error before you start the loop:

Local NumberVar i;
If UBound(Holidays) > 0
Then
For i := 1 to Count(Holidays)
...etc

Naith
 
This formula was created to be referenced by the other formula. I am over my head on this, I thought pasting these formulas in a different report would give me the same results.
BeforeReadingRecords;
dateVar array Holidays := [
Date(2002,01,01),
Date(2002,01,18),
Date(2002,01,21),
Date(2002,02,18),
Date(2002,05,27),
Date(2002,07,04),
Date(2002,07,05),
Date(2002,09,02),
Date(2002,10,14),
Date(2002,11,28),
Date(2002,11,29),
Date(2002,12,24),
Date(2002,12,25),
Date(2003,01,01),
Date(2003,02,17),
Date(2003,05,26),
Date(2003,07,04),
Date(2003,09,01),
Date(2003,10,13),
Date(2003,11,11),
Date(2003,11,27),
Date(2003,11,28),
Date(2003,12,25)
];
0

 
Others may disagree with me on this, but I would suggest that you shy away from using BeforeReadingRecords and WhileReadingRecords.

Place your BeforeReadingRecords formula in your report header, and replace BeforeReadingRecords with WhilePrintingRecords.

Place your WhileReadingRecords formula at some point in the report, just taking care to ensure that it appears after the old BeforeReadingRecords formula. Replace WhileReadingRecords with WhilePrintingRecords.

Now give it another shot.

Naith
 
Thanks for your help. I inserted the array formula into the report header and seemed to solve the problem.
 
hi,
I have to use string array...
the foll code giving me same error

Local NumberVar i;
stringVar array myarray;
If UBound(myarray) > 0 Then
For i := 1 to Count(myarray)
Do
(
myarray := {EmployeeName}
);

Please help

Regards,
Khushi.
 
Hi all, I have a similar problem. I get the same message. But the message comes up around record 836. I know this because when I export I get an error (A subscript must be between 1 and the size of the array). The report runs fine in crystal reports but it doesnt want to export to any file format without error. My code is as follows...

(VB Syntax)
'Splits PositionCodeDescription into Jobdescription and Department Description

Dim StrArr() as String
Dim JobDesc as String

StrArr = Split ({vPOSITION_CODES.PositionCodeDescription},">>")
JobDesc = StrArr(1)

Formula = JobDesc

TIA
-Robert

Thanks
-Robert
System Analyst/Programmer
 
could it be that you have hit a null in the database??
hence there is no split value.

You are using Basic syntax and I don't know how exactly you test for nulls...you should do so and assign a blank space as the formula result if you find one

Jim Broadbent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top