Data saved in array not there when accessed!

 
//List is defines as list of double values

//I store the data -> I checked 
//A and B are just simplification and in my code they are names of constants for beter readability of code
eventList[A][B] = VAR1; //VAR1 = 4.0
//than I check value
if(eventList[A][B] > 0.0){
   //TRUE
}else {
   //FALSE
}
 
//Problem is result is FALSE!!!

Hi,

I have a problem which is driving me crazy. In my EA I need to use two dimensional array to save some structures of data. Problem is on one point, when I save data to one cell and later try to read it, the data is not there.

Code looks like int the example but I simplified it to strip unnecessary parts.

I would realy appreciate any help because I am realy out of ideas what is going on and it is driving me nuts.


Thanks

 
Probably because eventList[A][B] does not exist
 
wolfi3b:

Hi,

I have a problem which is driving me crazy. In my EA I need to use two dimensional array to save some structures of data. Problem is on one point, when I save data to one cell and later try to read it, the data is not there.

Code looks like int the example but I simplified it to strip unnecessary parts.

I would realy appreciate any help because I am realy out of ideas what is going on and it is driving me nuts.

Please show the relevant code, for example the array declaration.
 
//double eventList[1][4];
double eventList[][];
eventList[0][3] = 4.0; //VAR1 = 4.0
//than I check value
if(eventList[0][3] > 0.0){
   Alert("TRUE");
}else {
   Alert("FALSE");
}

//--------above code will return FALSE
//--------following code will return TRUE

double eventList[1][4];
//double eventList[][];
eventList[0][3] = 4.0; //VAR1 = 4.0
//than I check value
if(eventList[0][3] > 0.0){
   Alert("TRUE");
}else {
   Alert("FALSE");
}
 
double eventList[][];

The array has no size, so the assignment has failed (and set last error = 4002) the read also fails (setting 4002) and you get zero and zero is not greater than 0.0

Show us your declaration of eventList and the values of A and B

 

Hi, thanks for your answers.

Ok I wanted it to be like pseudocode to keep it simple. But Field looks like this ( I hope I did not forgot on something):

And one other important think - compilation without errors, while running this EA no error appeared in MetaTrader output.

//declaration of extern parameters

extern double listSize = 10;

//my EA variables

double eventList[1][7];

#define eventList_ORDER_ALLOWED        6

//function code

int init(){

   //...other non inportant code

    ArrayResize(eventList,listSize);   

   //...other non inportant code

   return(0);

}

//This methods IS called in EA
void someMethodInMyCode(){

    int eventCount =  ArraySize(eventList);
    double orderAllowedType = MyMEthodReturningDoubleValue();//this method I checked returns correct value, for example 2.0

    //...other non inportant code

    for(int i = 0; i < eventCount; i++){

        //...other non inportant code

        eventList[i][eventList_ORDER_ALLOWED] = orderAllowedType; 

        //...other non inportant code

    }

}

//This methos IS called after previouse one.
void someOtherMethod(int index){
     //...other non inportant code
     Print("Value: " + eventList[index][eventList_ORDER_ALLOWED]);
     //...other non inportant code
}

I realy appreciate your help...

 
wolfi3b:

Hi, thanks for your answers.

Ok I wanted it to be like pseudocode to keep it simple. But Field looks like this ( I hope I did not forgot on something):

And one other important think - compilation without errors, while running this EA no error appeared in MetaTrader output.


I realy appreciate your help...


This is where your issue lies . . .

    int eventCount =  ArraySize(eventList);
    double orderAllowedType = MyMEthodReturningDoubleValue();//this method I checked returns correct value, for example 2.0

    //...other non inportant code

    for(int i = 0; i < eventCount; i++){

        //...other non inportant code

        eventList[i][eventList_ORDER_ALLOWED] = orderAllowedType; 

ArraySize gets the total element count, in this case the array is 10 elements ( due to the resize ) by 7 elements, so 70 elements. Your loop will go from 0 to 69 and use that value for the first dimension . . .

eventList[i][eventList_ORDER_ALLOWED] = orderAllowedType; 

. . . this is obviously wrong.


Don't use ArraySize() use ArrayRange()

 
double eventList[1][7];                     // Since you're resizing use eventList[][7]

#define eventList_ORDER_ALLOWED        6

    ArrayResize(eventList,listSize);        // eventList is now [10][7]

    int eventCount =  ArraySize(eventList); // eventCount is now 70.
you want eventCount = ArrayRange(eventList,0); // eventCount is 10 rows
 

Thank you! ArrayRange did it. I can not believe how I could be so blind.

Reason: