Download MetaTrader 5
To add comments, please log in or register
Follow the news. View our company's official channel!
Gordon Gekko
664
Gordon Gekko 2016.07.18 20:11 

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
13641
whroeder1 2016.07.19 19:38  
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
1523
Fernando Carreiro 2016.08.20 15:34  
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