Declare 2 dimensional array and assign array

 

I would like to know how to declare a two dimensional array and assign values to it.

I have the following code. But it doesn't work.

string arrprice[7][1];

arrprice[0][0]="AAA1";

arrprice[0][1]="1.234678";

Above doesn't work. Tried the following and same issue.

arrprice[1,0]="AAA1";

arrprice[1,1]="1.234678";


 
arrprice[0][1]="1.234678";

The second dimension has only 1 element so you cannot access element 1, only element 0

You should get an array out of range error 

 
Thanks a lot.
 
Keith Watford:

The second dimension has only 1 element so you cannot access element 1, only element 0

You should get an array out of range error 

Is this correct?

//+------------------------------------------------------------------+ 
//| Expert initialization function                                   | 
//+------------------------------------------------------------------+ 
int OnInit()
  {
   return(INIT_SUCCEEDED);
  };
//+------------------------------------------------------------------+ 
//| Expert deinitialization function                                 | 
//+------------------------------------------------------------------+
int OnDeinit()
{
   Comment("");
};
//+------------------------------------------------------------------+ 
//| Expert tick function                                             | 
//+------------------------------------------------------------------+
void OnTick()
{
   Comment("iBovespa: "+(string)iBovespa());
};

double iBovespa()
{
   string iBovWeights[][2];
   iBovWeights = 
   {
      {"ABEV3","0.0506"},
      {"B3SA3","0.0393"},
      {"BBAS3","0.0431"},
      {"BBDC3","0.0164"},
      {"BBDC4","0.0867"},
      {"BBSE3","0.0124"},
      {"BRAP4","0.0047"},
      {"BRDT3","0.0057"},
      {"BRFS3","0.0120"},
      {"BRKM5","0.0084"},
      {"BRML3","0.0074"},
      {"BTOW3","0.0051"},
      {"CCRO3","0.0099"},
      {"CIEL3","0.0077"},
      {"CMIG4","0.0088"},
      {"CSAN3","0.0041"},
      {"CSNA3","0.0040"},
      {"CVCB3","0.0057"},
      {"CYRE3","0.0028"},
      {"ECOR3","0.0014"},
      {"EGIE3","0.0062"},
      {"ELET3","0.0053"},
      {"ELET6","0.0049"},
      {"EMBR3","0.0105"},
      {"ENBR3","0.0030"},
      {"EQTL3","0.0109"},
      {"ESTC3","0.0057"},
      {"FLRY3","0.0044"},
      {"GGBR4","0.0097"},
      {"GOAU4","0.0027"},
      {"GOLL4","0.0021"},
      {"HYPE3","0.0086"},
      {"IGTA3","0.0023"},
      {"ITSA4","0.0381"},
      {"ITUB4","0.1064"},
      {"JBSS3","0.0133"},
      {"KLBN11","0.0071"},
      {"KROT3","0.0098"},
      {"LAME4","0.0092"},
      {"LOGG3","0.0003"},
      {"LREN3","0.0190"},
      {"MGLU3","0.0079"},
      {"MRFG3","0.0015"},
      {"MRVE3","0.0027"},
      {"MULT3","0.0043"},
      {"NATU3","0.0050"},
      {"PCAR4","0.0092"},
      {"PETR3","0.0504"},
      {"PETR4","0.0707"},
      {"QUAL3","0.0023"},
      {"RADL3","0.0090"},
      {"RAIL3","0.0131"},
      {"RENT3","0.0095"},
      {"SANB11","0.0115"},
      {"SBSP3","0.0084"},
      {"SMLS3","0.0017"},
      {"SUZB3","0.0160"},
      {"TAEE11","0.0036"},
      {"TIMP3","0.0066"},
      {"UGPA3","0.0189"},
      {"USIM5","0.0033"},
      {"VALE3","0.1056"},
      {"VIVT4","0.0130"},
      {"VVAR3","0.0013"},
      {"WEGE3","0.0090"}
   };
   double IBOV = 0.0;
   for(int i=0;ArraySize(iBovWeights)-1;i++)
      {
         SymbolSelect(iBovWeights[i][0],true);
         IBOV =+ SymbolInfoDouble(iBovWeights[i][0],SYMBOL_LAST)*StringToDouble(iBovWeights[i][1]);
      };
   IBOV = IBOV / 1.00002;
   return(IBOV);
};
Reason: