Download MetaTrader 5

ArrayFill question

To add comments, please log in or register
Gordon Gekko
622
Gordon Gekko  

Hi guys,

This code

#define N_ARRAY 5
   int myArray[];

   ArrayResize(myArray,N_ARRAY);

   Print("Before: ",myArray[0],"/",myArray[N_ARRAY-1]);
   ArrayFill(myArray,0,WHOLE_ARRAY,7);
   Print("After: ",myArray[0],"/",myArray[N_ARRAY-1]);

 gives 0/0 in "After" line.

But this code

#define N_ARRAY 5
   int myArray[];

   ArrayResize(myArray,N_ARRAY);

   Print("Before: ",myArray[0],"/",myArray[N_ARRAY-1]);
   ArrayFill(myArray,0,ArraySize(myArray),7);
   Print("After: ",myArray[0],"/",myArray[N_ARRAY-1]);

gives 7/7.

"WHOLE_ARRAY" doesn't work.

ArraySize(myArray) does work.

Why?

Thanks

whroeder1
16105
whroeder1  
ggekko: Why?
  1. WHOLE_ARRAY

    Used with array functions. Indicates that all array elements will be processed. Means the number of items remaining until the end of the array, i.e., the entire array will be processed

    -- Other constants - Named Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
  2. This is a user's forum not Metaquotes.
Fernando Carreiro
2960
Fernando Carreiro  
According to the documentation the, ArrayFill() function does not mention that you can use a count of 0 or WHOLE_ARRAY with that function. In other words, you have assumed it does, but it actually needs an explicit count. Only some array functions allow the use of a 0 count or WHOLE_ARRAY to mean the entire array, but ArrayFill() is not one of them.
To add comments, please log in or register