Hiariables

Back to topics list To post a new topic, please log in or register
avatar
1
mzc82 2016.08.24 14: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


avatar
1215
FMIC 2016.08.24 15: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.

avatar
13001
WHRoeder 2016.08.24 17: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");
    }
Back to topics list  

To add comments, please log in or register