Setting a Variable Whose Name is Contained Within a Separate Variable

 

Hi

I have an Array which contains names of variables. Is there a way to use the Array entries to assign a value instead of having to do...


                     if (Per_Array[i,0]) = "Ind0_DonchianPeriodsEntry"

                        Ind0_DonchianPeriodsEntry=GVResult

                     else

                     if (Per_Array[i,0]) = "Ind0_DonchianPeriodsExit"

                        Ind0_DonchianPeriodsExit=GVResult

                     else 

etc


Any help would be appreciated 



 
Neils:

Hi

I have an Array which contains names of variables. Is there a way to use the Array entries to assign a value instead of having to do...


There is, to my knowledge, no eval() functionality in MQL4/MQL5.

For your specific task, perhaps a hash would work for you.

https://www.mql5.com/en/forum/220383

Libraries: CDictionary class
Libraries: CDictionary class
  • 2017.11.20
  • www.mql5.com
CDictionary class: Author: Enrico Lambino...
 
Anthony Garot:


There is, to my knowledge, no eval() functionality in MQL4/MQL5.

For your specific task, perhaps a hash would work for you.

https://www.mql5.com/en/forum/220383

Hi Anthony,


Thank you for sharing your idea. Apologies,I really should have mentioned that I'm using MQL4 - Your suggestion looks to be MQL5 maybe.

 
Neils: Hi Anthony, Thank you for sharing your idea. Apologies,I really should have mentioned that I'm using MQL4 - Your suggestion looks to be MQL5 maybe.
Classes (OOP) works in both MQL4 and MQL5!
 
Neils:

Hi Anthony,


Thank you for sharing your idea. Apologies,I really should have mentioned that I'm using MQL4 - Your suggestion looks to be MQL5 maybe.

It should work in either platform, however, using mutable strings to specify state is a dangerous practice. I can't help but to think there is likely a better, simpler, and safer way to accomplish what you are ultimately trying to achieve.