How to pass array to a function

Back to topics list To post a new topic, please log in or register
avatar
26
winters 2015.02.28 16:10
 

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 ()

 


Attached files:
  test.mq4  (3.30 KB)
avatar
2017
gooly 2015.02.28 19:34 #
 

Your rerNum-array has the size 0,2;

ArrayResize(resNums,0);



avatar
Moderator
3406
GumRai 2015.02.28 21:39 #
 
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. 

avatar
26
winters 2015.03.01 17:55 #
 
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! 

Back to topics list  

To add comments, please log in or register