Creating Enum from Array?

 
string TEST_A[3] = {"TEST_A_1", "TEST_A_2", "TEST_A_3"};
string TEST_B[5] = {"TEST_B_1", "TEST_B_2", "TEST_B_3", "TEST_B_4", "TEST_B_5"};

string TESTEnum[8];
ArrayResize(TESTEnum, ArraySize(TEST_A)+ArraySize(TEST_B), ArraySize(TEST_A)+ArraySize(TEST_B)); 

   for(int i=0; i<ArraySize(TEST_A); i++)
   {
         TESTEnum[i] = TEST_A[i];
   }       
             
   for(i=0; i<ArraySize(TEST_B); i++)
   {
         TESTEnum[ArraySize(TEST_A)+i] = TEST_B[i];
   }

//Final result should be like this:

//enum TestEnum{ TEST_A_1=0, TEST_A_2=1, TEST_A_3=2, TEST_B_1=3, TEST_B_2=4, TEST_B_3=5, TEST_B_4=6, TEST_B_5=7 );

How to make custom Enumeration from TestEnum array values? 

I am really like using Enum, it simplify the input.

Thanks for the help.

 
wieb:

How to make custom Enumeration from TestEnum array values? 

I am really like using Enum, it simplify the input.

Thanks for the help.

Have you print the results of your code implementation using scripts?
 
wieb:

How to make custom Enumeration from TestEnum array values? 

I am really like using Enum, it simplify the input.

Thanks for the help.


You cannot define a type on-the-fly from a value. All types have to be defined at compile time.
 
Ex Ovo Omnia:

You cannot define a type on-the-fly from a value. All types have to be defined at compile time.


If all types have to be defined at compile time, meaning I have to manually typing the values one by one.

So in the conclusion... is it not possible creating Enum from Array values?

Is there any other way to make pull down input (just like Enum)?
 
wieb:


If all types have to be defined at compile time, meaning I have to manually typing the values one by one.

Yes

wieb:

So in the conclusion... is it not possible creating Enum from Array values?

Correct

wieb:

Is there any other way to make pull down input (just like Enum)?

No
 
honest_knave:

Yes

Correct

No

Thank you very much for the answer.
 
What do you want to achieve? Why do you need enum? Enum is actually an integer value with some extra type information.
 
wieb: How to make custom Enumeration from TestEnum array values?
  1. Why do you have any strings at all? Output the value (an int) read the value (and cast.)
  2. But if you insist
    enum TestEnum{ TEST_A_1, TEST_A_2, TEST_A_3, TEST_B_1, TEST_B_2, TEST_B_3, TEST_B_4, TEST_B_5);
       #define TestEnum_FIRST  TEST_A_1
       #define TestEnum_LAST   TEST_B_5
       #define TestEnum_COUNT (TEST_B_5+1)
    TestEnum testEnum(string v){
       for(TestEnum e = TestEnum_FIRST; e <= TestEnum_LAST; ++e)
          if(v == EnumToString(e) ) return e;
       return WRONG_VALUE;
    }
    //v Convert to enums
    string TEST_A[3] = {"TEST_A_1", "TEST_A_2", "TEST_A_3"};
    string TEST_B[5] = {"TEST_B_1", "TEST_B_2", "TEST_B_3", "TEST_B_4", "TEST_B_5"};
    
    TestEnum TESTEnum[TestEnum_COUNT];
    int i = 0;
       for(int i=0; i<ArraySize(TEST_A); i++) TESTEnum[i++] = testEnum(TEST_A[i]);
       for(i=0; i<ArraySize(TEST_B); i++)     TESTEnum[i++] = testEnum(TEST_B[i]);
    //^ Convert to enums
    
  3. You already have strings, you meant to convert to the enum.

  4. string TESTEnum[8];
    ArrayResize(TESTEnum, ...

    You can't resize an array that already has a fixed (8) size.

    ArrayResize - Array Functions - MQL4 ReferenceThe function can be applied only to dynamic arrays.
 
whroeder1:
  1. Why do you have any strings at all? Output the value (an int) read the value (and cast.)
  2. But if you insist

  3. This is wrong, you can't resize an array that already has a fixed (8) size. ArrayResize - Array Functions - MQL4 Reference


Contrary to the documentation, you actually can:

string test[10];
printf("Before resize: %i",ArraySize(test));
printf("After resize: %i",ArrayResize(test,5));

2017.03.22 15:03:19.578 TestScript Ger30Sb617,M80: After resize: 5

2017.03.22 15:03:19.578 TestScript Ger30Sb617,M80: Before resize: 10

 
honest_knave: Contrary to the documentation,
Means it works currently and could stop at any time.
 
whroeder1:
Means it work currently and could stop at any time.

Valid point, although it has worked for many years (appreciate that is no guarantee for the future).
Reason: