How to pass array to a function

 

hi, I had working mql4 expert, and after a new build it stopped to work as expected. Current build is 765

Namely, array passed to a function has no values.

 Please see attached full code and of its execution output:

void OnTick()
  {
ArrayResize(listOfLiveMNumbers,10,4);
ArrayResize(listOfStopMNumbers,10,4);
int resNums[][2];
ArrayResize(resNums,0);
      Print("listOfLiveMNumbers");
      ArrayPrintInt(listOfLiveMNumbers);
      Print("listOfStopMNumbers");
      ArrayPrintInt(listOfStopMNumbers);
ArrayMerge(listOfStopMNumbers, listOfLiveMNumbers, resNums);
   
  }
//+------------------------------------------------------------------+


int ArrayMerge(int &stopArray[][], int &liveArray[][], int &resultArray[][])
{
bool isfound=false;
int i=0,j=0,as=0;
if(ArraySize(liveArray)==0 || ArraySize(stopArray)==0) 
   {
      Print("ArrayMerge: both arrays must have values");  
      Print("liveArray");
      ArrayPrintInt(liveArray);
      Print("stopArray");
      ArrayPrintInt(stopArray);
      return(-1);
   }
..............

 

0       15:45:43        2012.01.02 00:00  test EURCHF,M30: listOfLiveMNumbers
0       15:45:43        2012.01.02 00:00  test EURCHF,M30: Array Size (ArrayPrintInt):20
0       15:45:43        2012.01.02 00:00  test EURCHF,M30: Array ([0][0]=0,[0][1]=0 ; [1][0]=0,[1][1]=0 ; [2][0]=0,[2][1]=0 ; [3][0]=0,[3][1]=0 ; [4][0]=0,[4][1]=0 ; [5][0]=0,[5][1]=0 ; [6][0]=0,[6][1]=0 ; [7][0]=0,[7][1]=0 ; [8][0]=0,[8][1]=0 ; [9][0]=0,[9][1]=0 ; )
0       15:45:43        2012.01.02 00:00  test EURCHF,M30: listOfStopMNumbers
0       15:45:43        2012.01.02 00:00  test EURCHF,M30: Array Size (ArrayPrintInt):20
0       15:45:43        2012.01.02 00:00  test EURCHF,M30: Array ([0][0]=0,[0][1]=0 ; [1][0]=0,[1][1]=0 ; [2][0]=0,[2][1]=0 ; [3][0]=0,[3][1]=0 ; [4][0]=0,[4][1]=0 ; [5][0]=0,[5][1]=0 ; [6][0]=0,[6][1]=0 ; [7][0]=0,[7][1]=0 ; [8][0]=0,[8][1]=0 ; [9][0]=0,[9][1]=0 ; )
0       15:45:43        2012.01.02 00:00  test EURCHF,M30: ArrayMerge: both arrays must have values
0       15:45:43        2012.01.02 00:00  test EURCHF,M30: liveArray
0       15:45:43        2012.01.02 00:00  test EURCHF,M30: Array Size (ArrayPrintInt):0
0       15:45:43        2012.01.02 00:00  test EURCHF,M30: Array ()
0       15:45:43        2012.01.02 00:00  test EURCHF,M30: stopArray
0       15:45:43        2012.01.02 00:00  test EURCHF,M30: Array Size (ArrayPrintInt):0
0       15:45:43        2012.01.02 00:00  test EURCHF,M30: Array ()

 


            
Files:
test.mq4  4 kb
 

Your rerNum-array has the size 0,2;

ArrayResize(resNums,0);
 
winters:

hi, I had working mql4 expert, and after a new build it stopped to work as expected. Current build is 765

Namely, array passed to a function has no values.

 Please see attached full code and of its execution output:

 

 

The arrays have values,but they are all zero as they are re-sized but not assigned any other values.

What your code does show is that when multi-dimensional arrays are passed by reference to a function, ArraySize() doesn't seem to work.

ArrayRange() does work though. 

 
GumRai:

The arrays have values,but they are all zero as they are re-sized but not assigned any other values.

What your code does show is that when multi-dimensional arrays are passed by reference to a function, ArraySize() doesn't seem to work.

ArrayRange() does work though. 

 

 

Thank you! 

Reason: