Help with array please

 

I wish to place external variables in an array.


I have tried this:

extern int       Int1=0;
extern string    PString1="";
extern string    SString1="";
extern int       Int2=0;
extern string    PString2="";
extern string    SString2="";


...

string a[2][3] = { DoubleToStr(Int1, 0), PString1, SString1, DoubleToStr(Int2, 0), PString2, SString2};//5 errors - "'0' variable expected", and 4 "')' unbalanced right parenthesis
string a[2][2] = { PString1, SString1, PString2, SString2};//error "comma or semicolon expected" before closing brace
string a[2][2] = { "PString1", "SString1", "PString2", "SString2"}; //no error but wrong result obviously


Any ideas?

 

1.

have u studied: MQL4 Reference - Basics - Variables - Initialization of variables

specifically: "All arrays, including those declared in the local scope, can be initialized with constants only."

2.

wat above means is that u can declare array: string a[2][3];

now... in 'code' u assign values to each array element as required

eg, a[0][0]=Int1;

3.

but... variable Int1 is type int, how able assign to variable of type string?

look at MQL4 Reference - Basics - Data types - Type casting

4.

string a[2][2] = { "PString1", "SString1", "PString2", "SString2"}; //no error but wrong result obviously

above works because via 1., are constants

to get contents/value of PString1,... into array element eg, a[0][1]=SString1;

.

maybe this help u get onto path?

 

Thanks, fbj, I found it shortly after posting and meant to come back and edit it. It is annoying because actually that list will be 96 variables long (36 * 3)!

Hopefully we will be allowed to Initialise with variables in MQL5

The Int is handled by DoubleToString(Int1,0) and then converting back on retrieval.

 

well, u sorted, good...

could always keyinto ini .txt file and read into array with FileReadString()..

then ez to mod entries etc.

just top of head comment :)

Reason: