Basic code. Help can you make this string array code work. - page 2

 
WHRoeder:

type name[] = { CONSTANT1, CONSTANT2 ...};

you're not using constants but variables.


Thankyou,

I didn't realise that the values had to be constants.

So the only option is the long winded way :(

 
GumRai:


Thankyou,

I didn't realise that the values had to be constants.

So the only option is the long winded way :(


string sampleArray[]={"EURUSD","USDJPY","GBPUSD"};
string temp="";

for(int x=0;x<ArraySize(sampleArray);x++)
{
     temp+=sampleArray[x]+"\n";     
}

Comment(temp);
 

Hey folks! Thanks so much you have solved it.

I think raptors fix stating the string array[] ={ ''aaa", "bbb"}; must be used at Global variable define time,

should be added to the Help code on arrays on the platform. Following that you just index each element "string result=array[0];"

I just could not find "string arrays defined" anywhere on Google that then compiled, let alone on MT4 forum.

I eventually heavy coded the separate indexed move procedure as below which works. Thanks everyone.

    int ac=0, numarray[3];
    string symchart, symarray[3];
    // load array elements seperately        
    symarray[ac] = "EURGBP"; numarray[ac] = 1; ac++; 
    symarray[ac] = "USDCHF"; numarray[ac] = 2; ac++;
    symarray[ac] = "USDJPY"; numarray[ac] = 3;
    symchart=symarray[2];
        
    Print("element 3 index 2 gives = "+symchart+"); // prints USDJPY
 
raven_chrono:

string sampleArray[]={"EURUSD","USDJPY","GBPUSD"};
string temp="";

for(int x=0;x<ArraySize(sampleArray);x++)
{
     temp+=sampleArray[x]+"\n";     
}

Comment(temp);

Thankyou,

very useful piece of code, but I had to change temp+= because it wouldn't compile.

but I don't see how this relates to my post