why does arraycopy not work?

 

Dear all

 

here is my code:

 

//+------------------------------------------------------------------+
//|                                                      testing.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property indicator_chart_window

int a[6] = {1,2,3,4,5,6};
int b[2][6];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

//---- 
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----

   ArrayCopy(b,a,1,0,4);
   
   Alert("b[0][0]= "+b[0][0]+", b[1][0]= "+b[1][0]+", b[1][3]= "+b[1][3]+", b[1][4]= "+b[1][4]);

//----
   return(0);
  }
//+------------------------------------------------------------------+

 

 I don't understand, all result shown are 0!

 

Can anybody tell me why?

 

Thx a lot!

 

 

wing 

 
Try printing b[0][1], b[0][2]...
 
WHRoeder:
Try printing b[0][1], b[0][2]...

I get it!  Thank you!
 

On the other hand, a new problem comes!

 

//+------------------------------------------------------------------+
//|                                                 1_1a_testing.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property indicator_chart_window

int a[1][1][6] = {21,22,23,24,25,26};
int b[4][2][6] = {1,2,3,4,5,6,7,8,9,10,11,12,0,0,0,0,0,18,0,0,0,0,0,0};
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

//---- 
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----

   Alert("----------------------------------------------------------");
   
   ArrayCopy(b,a,11,0,4);
   
   Alert("after, b0= "+b[0][0][0]+", b1= "+b[0][0][1]+", b2= "+b[0][0][2]+", b3= "+b[0][0][3]+", b4= "+b[0][0][4]+", b5= "+b[0][0][5]);
   Alert("after, b6= "+b[0][1][0]+", b7= "+b[0][1][1]+", b8= "+b[0][1][2]+", b9= "+b[0][1][3]+", b10= "+b[0][1][4]+", b11= "+b[0][1][5]);
   Alert("after, b12= "+b[1][0][0]+", b13= "+b[1][0][1]+", b14= "+b[1][0][2]+", b15= "+b[1][0][3]+", b16= "+b[1][0][4]+", b17= "+b[1][0][5]);

//----
   return(0);
  }
//+------------------------------------------------------------------+

 

 I do hope that the answer should be {1,2,3,4,5,6,7,8,9,10,11,21,22,23,24,0,0,18,0,0,0,0,0,0} but all values in the array didn't change.

 

Does anybody know how to correct it?

 

Thank you!

 

 

wing 

 
wing:

On the other hand, a new problem comes!

 I do hope that the answer should be {1,2,3,4,5,6,7,8,9,10,11,21,22,23,24,0,0,18,0,0,0,0,0,0} but all values in the array didn't change.

Does anybody know how to correct it?

What answer did you get ?
 
RaptorUK:
What answer did you get ?


"all values in the array didn't change"
 
wing:

"all values in the array didn't change"
Yes you said that already . . .  "What answer did you get ?"  which ones did change ?  which ones didn't change ?
 
wing:

I do hope that the answer should be {1,2,3,4,5,6,7,8,9,10,11,21,22,23,24,0,0,18,0,0,0,0,0,0} but all values in the array didn't change.

Does anybody know how to correct it?

wing:

"all values in the array didn't change"

The code that you have posted (reproduced below with some cosmetic changes) compiles but produces a runtime error (code 4056).

int a[1][1][6] = {21,22,23,24,25,26};
int b[4][2][6] = {1,2,3,4,5,6,7,8,9,10,11,12,0,0,0,0,0,18,0,0,0,0,0,0};
   
ArrayCopy(b,a,11,0,4);
   
Print ("Error Code = ", GetLastError());
   
Print (b[0][0][0], ", ", b[0][0][1], ", ", b[0][0][2], ", ", b[0][0][3], ", ", b[0][0][4], ", ", b[0][0][5], ", ", 
       b[0][1][0], ", ", b[0][1][1], ", ", b[0][1][2], ", ", b[0][1][3], ", ", b[0][1][4], ", ", b[0][1][5], ", ",
       b[1][0][0], ", ", b[1][0][1], ", ", b[1][0][2], ", ", b[1][0][3], ", ", b[1][0][4], ", ", b[1][0][5]);

ArrayCopy Test Example #1 

 
Thirteen:

The code that you have posted (reproduced below with some cosmetic changes) compiles but produces a runtime error (code 4056).

 



but MT4 did it successfully in case of arraycopy for 1 dimension to 2 dimension array.

 

//+------------------------------------------------------------------+
//|                                                 1_1b_testing.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property indicator_chart_window

int a[1][6] = {21,22,23,24,25,26};
int b[2][6] = {1,2,3,4,5,6,7,8,9,10,11,12};
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   ArrayCopy(b,a,5,0,4);
   
   Alert ("Error Code = ", GetLastError());
   
   Alert("after, b0= "+b[0][0]+", b1= "+b[0][1]+", b2= "+b[0][2]+", b3= "+b[0][3]+", b4= "+b[0][4]+", b5= "+b[0][5]);
   Alert("after, b6= "+b[1][0]+", b7= "+b[1][1]+", b8= "+b[1][2]+", b9= "+b[1][3]+", b10= "+b[1][4]+", b11= "+b[1][5]);

//---- 
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+

 

 

Does it mean that MT4 cannot perform arraycopy on 1 to 3 dimension array?  

Reason: