Call variable dynamically

 

Hi,

I would want to know, if it's possible to call dynamically variables.

For example:

I create 3 variabless:

string Var1,var2,var3

And I call them in a loop like this:

for(i=1;i<4;i++)

{

print(var+i);

}

When I compile, i have an error:" var+i didn't declare".

Do you have solution please?

Thank's a lot for your answer.

 

This is not allowed with mql4.

you have to use other method, for example use an array : var[3]

 

Thank's, so the problem with an array that must it be initialize by constant and not dynamically; Is it exact? otherwise explain me how can id do please?


Thank's a lot.

 
string Arr[3] = {Var1,var2,var3}

for(i=0;i<3;i++) {
   print(Arr[i]);
}
Is that what you mean?
 

Cannot declare Arrays with Variables.

 
ubzen:

Cannot declare Arrays with Variables.


oh ok. Well the Arr declaration is to replace the OP's Var1, Var2 and Var3 declarations so he should be able to do it. I just don't know what the values are. e.g.:

string Arr[3] = {"hello","hi","how are you?"}