Download MetaTrader 5

array out of range for dynamic array

To add comments, please log in or register
zifu wang
636
zifu wang  

What's wrong with following code?

//+------------------------------------------------------------------+
//|                                                          bbb.mq5 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   double  aaa[];
   aaa[1]=0;
  }
//+------------------------------------------------------------------+


2014.02.11 20:02:06.102    bbb (EURUSD,M1)    array out of range in 'bbb.mq5' (16,7)

Rodrigo Malacarne
Moderator
10372
Rodrigo Malacarne  
kwang1:

What's wrong with following code?


2014.02.11 20:02:06.102    bbb (EURUSD,M1)    array out of range in 'bbb.mq5' (16,7)

You have to specify the size of your dynamic array. You can do this by using the ArrayResize() funtion.

   double  aaa[];
   ArrayResize(aaa,2);
   aaa[0]=10;
   aaa[1]=20;
   Print("aaa[1] = "+DoubleToString(aaa[1]));
zifu wang
636
zifu wang  
Malacarne:

You have to specify the size of your dynamic array. You can do this by using the ArrayResize() funtion.

thanks a lot.........
To add comments, please log in or register