Array index out of bounds

Here’s the formula that’s giving me the error:

@For(n := 1; n <= @Elements(plantchoices); n := n + 1;

total := “”;

total:=total:@Text(@TextToNumber (temp1[n])+@TextToNumber (temp2[n])+@TextToNumber (temp3[n])+@TextToNumber (temp4[n])+@TextToNumber (temp5[n])+@TextToNumber (temp6[n])+@TextToNumber (temp7[n])+@TextToNumber (temp8[n])+@TextToNumber (temp9[n])+@TextToNumber (temp10[n])+@TextToNumber (temp11[n])+@TextToNumber (temp12[n]))

);

@If(@IsError(total);“0”;@Trim(total))

Plantchoices is a computed for display field that holds the choices of a checkbox as they’re checked.

The temp1 to temp12 fields calculate items in an order for each month that is in a date range. An example code for one of these fields is here:

aa := @Subset(@DbName; 1);

bb := @LeftBack(@Subset(@DbName; -1); “\”) + “\sales.nsf”;

thismonth:=@Adjust(fromdate;0;5;0;0;0;0);

firstdayofmonth:=@Date(@Year(thismonth);@Month(thismonth);1);

lastdayofmonth:= @Day(@Adjust(firstdayofmonth;0;1;-1;0;0;0));

endday:= @If(@Month(thismonth) = @Month(todate);@Day(todate);lastdayofmonth);

startday:= 1;

@If(@Middle(monthcheck;5;1) = “0”;@Return(“0”);

@For(n := 1; n <= @Elements(plantchoices); n := n + 1;

thewarehouse := @Trim(@Right(plantchoices[n];4));

newthing := “”;

thing := “”;

@For(DateNum := startday; DateNum <= endday; DateNum := DateNum + 1;

TheDateToUse:=@Adjust(firstdayofmonth;0;0;DateNum;0;0;0);

key := @Text(@Year(TheDateToUse)) + @Trim(@Right(“0”+@Text(@Month(thedatetouse));2)) + @Trim(@Right(“0” + @Text(@Day(TheDateToUse));2))+ @Trim(@Text(@Trim(thewarehouse)));

key2 := @Text(@Year(TheDateToUse)) + @Trim(@Right(“0”+@Text(@Month(thedatetouse));2)) + @Trim(@Right(“0” + @Text(@Day(TheDateToUse));2))+ @Trim(@Text(@Trim(thewarehouse)))+ “YY”;

key3 := @Text(@Year(TheDateToUse)) + @Trim(@Right(“0”+@Text(@Month(thedatetouse));2)) + @Trim(@Right(“0” + @Text(@Day(TheDateToUse));2))+@Trim(@Text(@Trim(thewarehouse)))+ “ZZ”;

thing:=@If (@IsError(

@DbLookup(“”:“Cache”;aa:bb; “(InvoicesByQtyWarehouse)”;@Trim(key);2));“0”;@DbLookup(“”:“Cache”;aa:bb; “(InvoicesByQtyWarehouse)”;key;2));

YY := @If (@IsError(

@DbLookup(“”:“Cache”;aa:bb; “(InvoicesByPartWarehouse)”;key2;2));“0”;@DbLookup(“”:“Cache”;aa:bb; “(InvoicesByPartWarehouse)”;key2;2));

ZZ := @If (@IsError(

@DbLookup(“”:“Cache”;aa:bb; “(InvoicesByPartWarehouse)”;key3;2));“0”;@DbLookup(“”:“Cache”;aa:bb; “(InvoicesByPartWarehouse)”;key3;2));

newthing := newthing:@Text(@Round(@TextToNumber(thing)-@TextToNumber(YY)-@TextToNumber(ZZ)))

);

blah:=blah:@If(@Text(@Sum(@TextToNumber(@Text(@Trim(newthing))))) = “@ERROR”;“stup”;@Text(@Sum(@TextToNumber(@Text(@Trim(newthing))))))

));

@Trim(blah)

The first formula at the top is the one giving me the error.

Thanks for any help

KB

Subject: RE: Array index out of bounds…

You need to check the inputs to your formula. As is so often the case, the source of the problem is elsewhere than where an error message is displayed.

The formula at the top assumes that all those temp fields have the same number of elements as plantchoices, and in fact that is evidently not the case; at least one has fewer. You posted the formula for a temp field but it is long and complex and I have no time to analyze it. You need to debug it and see where it’s going wrong. There are some tips here for debugging formulas: Debugging Domino Applications part 1 and part 2.

Incidentally, the + operator, given two lists of numbers which are the same length, returns a list where each element is the sum of the corresponding elements of the original list. You don’t really need a loop here (and if you did need a loop, you might want to initialize total outside the loop.

Subject: RE: Array index out of bounds…

Thanks Andre for the input. I appreciate it. I’ll poke at it tomorrow with your recommendations

KB