Array index is out of bounds.

when I am running customer balance confirmtion report.I receive the array indx is out of bounds.the reports gives error only on selected customer account for the rest inputs it works fine.following is the error

Error executing code: Array index -8 is out of bounds.

(C)\Classes\Global\numeralsToTxt_AR - line 39
(C)\Reports\DOSCustBalanceConfirmation\Designs\CustBalanceConfirmation\AutoDesignSpecs\Body:CustTable_Body\Methods\balanceInWords
(C)\Classes\ReportSection\executeSection
(C)\Classes\ReportRun\send
(C)\Reports\DOSCustBalanceConfirmation\Methods\fetch
(C)\Classes\ReportRun\run
(C)\Classes\SysReportRun\run - line 26
(C)\Classes\RunBaseReport\run - line 34
(C)\Classes\SysReportRun\run

Thanks.

If you’re a developer, look at what’s going on at line 39 of numeralsToTxt_AR(). If you’re not a developer, ask your development team or your implementation partner to do it.

Thank your martin for the reply.

I checked with the code it looks good to me.I am getting this error for one customer only for the rest everything is ok.

here is the code

static TempStr numeralsToTxt_AR(real _num)
{
real numOfPennies = decround(frac(_num), 2);
real test = _num - frac(_num);
str zero;
str comma;
str and;
str cent;
int numOfTenths;
str 20 ones[19], tenths[9], hundreds, thousands, millions, billions, trillions;

int64 temp;
str 200 returntxt;

real modOperator(real a1, real a2)
{
int tmpi;
real tmp1, tmp2;
tmp1 = a1 / a2;
tmpi = real2int(tmp1);
tmp2 = tmpi;
return (tmp1 - tmp2)*a2;
}

str doubleDigit2ARTxt(real doubledigit,boolean _pennies = false)
{
str txt;
int firstDigit;
real tempdigit;

if(_pennies)
{
firstDigit = doubledigit * 10;
doubledigit = doubledigit * 100;
if(!firstDigit)
{
doubledigit = doubledigit mod 10;
//txt = zero + " " + ones[doubledigit];
txt = ones[doubledigit]; /// this is line 39
return txt;
}
}

I’m not so sure that the code is OK. If you call doubleDigit2ARTxt() with -0.08, you’ll get an array index -8, which is clearly wrong. This seems to be what happened in your case. Note that the code above doesn’t show how doubleDigit2ARTxt() is used, therefore I can’t comment on it.

Whether you’ll get this error or not clearly depends on what number is used as the input, which explains why it doesn’t happen for all customers.

If you’re unable to identify the cause by a static review, you’ll have to use debugging.

Dear Martin,

yes you are correct with -0.08 I will get and for other company as well.for this doubleDigit2ARTxt() Assignment/Comparison loses precision warning it shows.kindly check and suggest,Thank you very much

if(numOfPower > 2 && _power > 100)
{
returntxt = returntxt ? (returntxt + and + doubleDigit2ARTxt(real2int(numOfPower))) : (returntxt + ’ ’ + doubleDigit2ARTxt(real2int(numOfPower)));
}