Download MetaTrader 5
To add comments, please log in or register
Interested in earning money via MQL5 Cloud Network? Enter your profile!
pacman992
30
pacman992 2016.01.14 08:17 
i dont know why but it always return zero, help
double test_array[];
int i;
i=1;

int init(){
return (0);
}

int start(){

test_array[i]=3.2;
alert("value = "+ test_array[i]);

return (0);
}

int deinit{
return (0);
}
honest_knave
Moderator
1837
honest_knave 2016.01.14 08:19  

Your array has no size, so it contains no elements.

If you specify i=1, that is the second element (0 would be the index of the first element).

So your array size must be at least 2 for your code to work.

pacman992
30
pacman992 2016.01.14 08:25  
honest_knave:

Your array has no size, so it contains no elements.

If you specify i=1, that is the second element (0 is the first).

So your array size must be at least 2 for your code to work.

 

sorry what do u mean with array size? could you make an example? 
honest_knave
Moderator
1837
honest_knave 2016.01.14 08:38  

An array needs a size. It could be 1, 10, 15, 37 or whatever number takes your fancy. But it can't be unspecified.

double test_array[]; // this has no size

double test_array[2]; // this has 2 elements

double test_array[];
ArrayResize(test_array,5); // this has 5 elements

 

You can read more about Arrays in MQL4 here

 

As a tip, I recommend you use this at the top of your code. It would have shown you your problem in the Experts log (Array out of range error).

#property strict
pacman992
30
pacman992 2016.01.14 08:46  
honest_knave:

An array needs a size. It could be 1, 10, 15, 37 or whatever number takes your fancy. But it can't be unspecified.

 

You can read more about Arrays in MQL4 here

 

As a tip, I recommend you use this at the top of your code. It would have shown you your problem in the Experts log (Array out of range error).

 

thank you sir, you help me a lot
honest_knave
Moderator
1837
honest_knave 2016.01.14 08:59  
My pleasure, I'm glad it helped.
/
To add comments, please log in or register