Download MetaTrader 5
To add comments, please log in or register
Create interesting Forum topics concerning the automated trading!
Micky
58
Micky 2010.09.09 19:32 

I made a simple test script.

//+------------------------------------------------------------------+
//|                                                     testEnum.mq5 |
//+------------------------------------------------------------------+
enum ENUM_TEST_CODE
  {
   CODE_ZERO,
   CODE_ONE,
   CODE_TWO
  };
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- expect to print out number 3
   Print(getCode("0")+getCode("1")+getCode("2"));
//--- expect to print out string "012"
   Print((string)getCode("0")+(string)getCode("1")+(string)getCode("2"));
  }
//+------------------------------------------------------------------+
//| User-defined function                                            |
//+------------------------------------------------------------------+
ENUM_TEST_CODE getCode(string textcode)
  {
   if(textcode=="0") return(CODE_ZERO);
   if(textcode=="1") return(CODE_ONE);
   if(textcode=="2") return(CODE_TWO);
   return(CODE_ZERO);
  }
//+------------------------------------------------------------------+

And results are like this:

2010.09.10 00:19:00 testEnum (EURUSD,M5) 3 < correct.
2010.09.10 00:19:00 testEnum (EURUSD,M5) 260830442608302026082984 < incorrect... I expected string "012".
 

Max Payne
411
Max Payne 2010.09.09 22:21  

Well, I'm not sure whether actually casting a string from an enumeration through the cast operator is the preferred MQL5 way of doing things.

Though it's not so orthogonal, use: IntegerToString() instead. 

Micky
58
Micky 2010.09.10 06:09  

Thanks, Plymo, for your reply.

If it will be clear that the spec was changed, I will use IntegerToString().

Ilyas
1204
Ilyas 2010.09.10 13:11  
Micky:

I made a simple test script.

And results are like this:

2010.09.10 00:19:00 testEnum (EURUSD,M5) 3 < correct.
2010.09.10 00:19:00 testEnum (EURUSD,M5) 260830442608302026082984 < incorrect... I expected string "012".
 

Thank you for your message. Buh fixed. Please wait for updates.
/
To add comments, please log in or register