How to make custom Enumeration from TestEnum array values?
I am really like using Enum, it simplify the input.
Thanks for the help.
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.
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)?If all types have to be defined at compile time, meaning I have to manually typing the values one by one.
Yes
So in the conclusion... is it not possible creating Enum from Array values?
Correct
Is there any other way to make pull down input (just like Enum)?
Yes
Correct
NoThank you very much for the answer.
- Why do you have any strings at all? Output the value (an int) read the value (and cast.)
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
- You already have strings, you meant to convert to the enum.
string TESTEnum[8]; ArrayResize(TESTEnum, ...
You can't resize an array that already has a fixed (8) size.
ArrayResize - Array Functions - MQL4 Reference The function can be applied only to dynamic arrays.
- Why do you have any strings at all? Output the value (an int) read the value (and cast.)
But if you insist 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. |
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).
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How to make custom Enumeration from TestEnum array values?
I am really like using Enum, it simplify the input.
Thanks for the help.