Download MetaTrader 5
To add comments, please log in or register
Deposit to your account via WebMoney
mzc82
6
mzc82 2016.08.24 12:45 

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


Fernando Carreiro
1574
Fernando Carreiro 2016.08.24 13:26  

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.

whroeder1
13656
whroeder1 2016.08.24 15:24  
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");
    }
/
To add comments, please log in or register