Hiariables

 

Hi,

I variables with the name that is variable.
I try to explain:

double highprecEURUSD = 0;

double highprecUSDEUR = 0;

check ("EURUSD");

void check( string valute){

Print(highprec + valute);

}


I would like to print the value of the variable depending on the string passed to the function check.

Help me.

Thanks

Marco


 

No, the MQL language is not interpreted at run-time. It is compiled, so you cannot have "variable" variable names. You will have to use other alternatives, such as Key-Value Collections (implemented as classes or even as arrays) to achieve similar constructs. To do that, you will have to some research into the subject, as well as learn other general coding practices for compiled coding languages.

 
mzc82: I would like to print the value of the variable depending on the string passed to the function check.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Do exactly what you said.
    void check( string valute){
       if(     valute == "EURUSD") Print(highprecEURUSD);
       else if(valute == "USDEUR") Print(highprecUSDEUR);
       else                        Print("UNVALID");
    }