I am wondering if there is a way to initialize a string with a constant plus the value of a variable.
Is there a way to do this or do I have use a include file and initialize 100s of 1000s of similar strings
As an exsample:
you should use
"A"+DoubleToStr(x,0)
sn
Sorry, I don't think I made my queston clear. I don't want to assign a variable "A"+x, I want to create the variable "A"+x a.k.a A1 so I can assign it a value to it, for example A1=5 so-> 5+StrToDouble(A1)=10. I get an A-variable expected error with-> string "A"+x. I have als tried StringConcatenate but that won't work either.
Does anyone know how to do this?
Sorry, I don't think I made my queston clear. I don't want to assign a variable "A"+x, I want to create the variable "A"+x a.k.a A1 so I can assign it a value to it, for example A1=5 so-> 5+StrToDouble(A1)=10. I get an A-variable expected error with-> string "A"+x. I have als tried StringConcatenate but that won't work either.
Does anyone know how to do this?
I understood your question, you are talking about the variable name not it's value, talking about initializing a variable probably sent people off on the wrong direction . . . I don't know for a fact but I suspect that what you want to do isn't possible.
Perhaps if you explain what you are trying to achieve (end result) there may be another way to implement it . . .
- Sent me off.
- If you want a collection of variables, use an array
initialized to constants:
int A[] = { 10, 20, 30, 40 }; // A[2] == 30
non-constants:
int A[4]; A[0] = 1*10; A[1] = 2*10; A[2] = 3*10; A[3] = 4*10;
- If you want given a string set/get a value, create a table with access functions
SetValue("A", 10); SetValue("B", 20); SetValue("C", 30); SetValue("D", 40); int v = GetValue("C"); // 30 ====================== string key[]; int value[]; void SetValue(string key_, int value_){ int iLimit = ArraySize(key) for (int iKey = 0; iKey < iLimit; iKey++){ if (key[iKey] == key_){ value[iKey] = value_; return; } // Existing } ArrayResize(key, iLimit+1); key[iLimit] = key_; // New ArrayResize(value, iLimit+1); value[iLimit] = value_; } #define INF 0x6FFFFFFF // Not quite infinite, Jul 2029, or 1,879,048,191 int GetValue(string key_){ int iLimit = ArraySize(key) for (int iKey = 0; iKey < iLimit; iKey++){ if (key[iKey] == key_){ return(value[iKey]); } // Existing } return(INF); // Not found }
Number 2 might work if I wanted to inialize a bunch of var's at once but I want to avoid that and I also need a way to refer to them later on without the full name. Idealy I want to be able to do this:
static int increasingnumber; increasingnumber++; string "A"+increasingnumber;//"A"+increasingnumber doesen't work string "B"+increasingnumber;//"B"+increasingnumber doesen't work "A"+increasingnumber=12; "B"+increasingnumber=235; if(DoubleToStr("B"+increasingnumber)>otherbumber) { //something }
//I need to replace "A"+increasingnumber with something that works
Not sure I understand why you can use arrays . . .
string A[100]; //"A"+increasingnumber doesen't work string B[100]; //"B"+increasingnumber doesen't work static int increasingnumber; increasingnumber++; A[increasingnumber] = 12; B[increasingnumber] = 235; if(DoubleToStr(B[increasingnumber])>otherbumber) { //something }
You saved my life RaptorUK, now I don't have to scrap hours of code. I was about to give up on the people of MQL4 forum and was worried there was nothing built in mql4 to do such a seemingly simple thing. Thanks again.
You saved my life RaptorUK, now I don't have to scrap hours of code. I was about to give up on the people of MQL4 forum and was worried there was nothing built in mql4 to do such a seemingly simple thing. Thanks again.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am wondering if there is a way to initialize a string with a constant plus the value of a variable.
Is there a way to do this or do I have use a include file and initialize 100s of 1000s of similar strings
As an exsample:
string A1;