How to get length of enum and item in MQL4/MQL5 ? - page 2

 
Alain Verleyen:
The length is never unknown and this topic is just resulting from a bad design.
This requirement comes from an AutoTester project.
In many Indicators/EAs, input parameters contain custom enum, we need to figure out what item(and relative value) in enum.
So, don't say "bad design". Blah...blah...
 
Xiangdong Guo:
This requirement comes from an AutoTester project.
In many Indicators/EAs, input parameters contain custom enum, we need to figure out what item(and relative value) in enum.
So, don't say "bad design". Blah...blah...
Of course it's a bad design. But it's not a problem for me.
 
Marco vd Heijden:
What do you mean "length of enum"?
enum fruit
  {
   APPLE=0,//APPLE
   BANANA=1,//BANANA
   GRAPE=2,//GRAPE
   ORANGE=3,//ORANGE
   CARROT=4,//CARROT
  };
  
sinput fruit type;//PICK A FRUIT 

Maybe carrot is not a fruit... i still don't understand what Xiangdong Guo means by 'length of enum'

The number of letters from each options string name?

How many options possible?

The numerical value of the option?

Not only bad design but also not very clear about what he means.

 
Marco vd Heijden:
The number of values, so 5 in your example of fruits.
 
Alain Verleyen:
The number of values, so 5 in your example of fruits.

I agree it's static it can not be variable so will always be a known fixed value to start with.

However if Xiangdong Guo is testing indicators that he did not design or write himself, and wants to know or detect input parameters automatically...

Not sure how knowing the number of available options could help, perhaps he wants to cross test all available options and is simply looking for the number of tests to run?

i would scan for the assumed options to resolve these values once you try to convert out of the borders of the available options it will generate cannot convert enum error since it does not exist.

 
Marco vd Heijden:

MT4/MT5 use C++/C# function to retrieve item from enum. But MetaQuotes doesn't port those functions to MQL4/MQL5. Hum...hum...

enum DURATION_INTERVALS  // Enumeration of named constants
   {
    month=1,     // Interval of one month
    two_months,  // Two months
    quarter,     // Three months - quarter
    halfyear=6,  // Half a year
    year=12,     // Year - 12 months
   };

input DURATION_INTERVALS HistoryDuration = month;

 

 
Xiangdong Guo:

MT4/MT5 use C++/C# function to retrieve item from enum. But MetaQuotes doesn't port those functions to MQL4/MQL5. Hum...hum...

 

Which function ? What is the problem ? Why do you want to loop through enum's items ?
 
Alain Verleyen:
Which function ? What is the problem ? Why do you want to loop through enum's items ?

If someone wants/need to do something what is not possible with MQL it does not necessarily mean "bad design". 

To topic starter: it is not possible to do what you want in current version of MQL.

The only way is to copy all items into an array and make your loop using that array. But it is only doable when/if you can modify the code.

 
Andrey Barinov:

If someone wants/need to do something what is not possible with MQL it does not necessarily mean "bad design". 

To topic starter: it is not possible to do what you want in current version of MQL.

The only way is to copy all items into an array and make your loop using that array. But it is only doable when/if you can modify the code.

Using an enum instead of an array is a bad design. Isn't ?

 
Alain Verleyen:

Using an enum instead of an array is a bad design. Isn't ?

No, using an array instead of enum is a bad design.

Example: Imagine you have a string value. And the task is to find out if this string is equal/contains in it one of the enum items names (EnumToString()).

How would you solve this?