Error 4002 Array out of Range

 

Hello I dont like this Error any more but every Time I get it :-)



It about Error 4002, Array index out oft Range, it comes when I make a if staement in a loop:



if( ArrayMinimum(Mart,cPeriod,Shift+1) )



The Array is "Mart".



Ok I dont know what to write the problem is clear, or not?

Did one understand the problem about this and how I can slove?

 

Show your code...

How have you declared/initialized your array?

 

Here is the function:

void Drawing(int Shift)
{

if(Shift>=0 && Shift+1<ArrayRange(Mart,0))

{

if(ArrayMinimum(Mart,cPeriod,Shift+1)<ArrayRange(Mart,0))

{
}

}
return;
}

The function is called by a loop.

----------

The Array is declared in the init() function and as a gloabl Array: double Mart[]; init(){ SetIndexBuffer(4,Mart);}

 
int ArrayMinimum( double array[], int count=WHOLE_ARRAY, int start=0)

If shift+1 is near the limit of the array, then when it checks cPeriod elements it may be going out of range.

Try with:

if(Shift>=0 && Shift+1+cPeriod<ArrayRange(Mart,0))

to see if the error stops

 
phy wrote >>
int ArrayMinimum( double array[], int count=WHOLE_ARRAY, int start=0)

If shift+1 is near the limit of the array, then when it checks cPeriod elements it may be going out of range.

Try with:

if(Shift>=0 && Shift+1+cPeriod<ArrayRange(Mart,0))

to see if the error stops

Now, really crazy and a bit awsome, it dont stop with your example.

The ArrayMinimum() statement makes the error and I dont no why.

 
Is cPeriod ever negative?
 

Sorry, but no, it is never negative, it is also a extern variable and always positiv.

I have make a if statement also to test it: if(cPeriod<0)Alert("<0"); but nothing happend.

The ArrayMinimum() statement makes the error and I dont no why.

But it can just be when the index is smaller than zero or bigger than the max size and this all I check before but it dont help.

 

Try

//replace this:
//if(ArrayMinimum(Mart,cPeriod,Shift+1)<ArrayRange(Mart,0))
int error = GetLastError();
int aMin = ArrayMinimum(Mart,cPeriod,Shift+1);
error = GetLastError();
      if(error == 4202)
      {
         Print( -- print out some diagnositics --);
      }
int aRange = ArrayRange(Mart,0));
error = GetLastError();
      if(error == 4202)
      {
         Print( -- print out some diagnositics --);
      }
if(aMin < aRange)

   {
    ...continue your code

I don't have any idea why you want to compare ArrayMinimum with ArrayRange.

ArrayMinimum gives an element number, so it should always be less than the size of the array.

Reason: