Download MetaTrader 5
To add comments, please log in or register
Documentation is available in CHM and PDF. Download it in any convenient form!
Dominic Gilbert
1632
Dominic Gilbert 2014.09.26 14:28 
Whats the simplest way of using an extern string "Yes" or "No" to activate or deactivate a void function?
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.09.26 14:57  
DomGilberto:
Whats the simplest way of using an extern string "Yes" or "No" to activate or deactivate a void function?

Something like this . . . off the top of my head, not tested . . .

extern string YesOrNo = "";


bool Yes = FALSE;


if(YesOrNo == "YES" || YesOrNo == "Yes" || YesOrNo == "yes") Yes = TRUE;


//call the function
A_Function(Yes)


// declare the function
void A_Function(bool lYes)
   {
   if(!lYes) return;
   
   //   rest of function . . .

   }
Dominic Gilbert
1632
Dominic Gilbert 2014.09.26 15:30  
Yea nice one thanks (all but moving the 1 at the end of "1Yes" like so "Yes1"). How could I go about having a drop down as an extern Yes or No? As opposed to writing it in the box within the parameters? (i.e. not a string but drop-down)
Carl Schreiber
5938
Carl Schreiber 2014.09.26 15:44  
DomGilberto:
Whats the simplest way of using an extern string "Yes" or "No" to activate or deactivate a void function?

I would suggest an enum (to tested!):

enum isBool {
        fs, // no, false
        tr  // yes, true
};
extern isBool   UseFuncA = fs;
extern isBool   UseFuncB = tr;
..
if ( UseFuncA == 1 ) x = funcA(..);
honest_knave
954
honest_knave 2014.09.26 15:46  
DomGilberto:
Yea nice one thanks (all but moving the 1 at the end of "1Yes" like so "Yes1"). How could I go about having a drop down as an extern Yes or No? As opposed to writing it in the box within the parameters? (i.e. not a string but drop-down)
enum YesOrNo {No=0,Yes=1};
extern YesOrNo ActivateFunction=Yes;

Edit: sorry gooly, must have posted at the same time.

whroeder1
13602
whroeder1 2014.09.26 18:07  
bool Yes = FALSE;

if(YesOrNo == "YES" || YesOrNo == "Yes" || YesOrNo == "yes") Yes = TRUE;
If must be in init.
bool Yes = FALSE;
OnInit(){
 Yes = YesOrNo == "YES" || YesOrNo == "Yes" || YesOrNo == "yes";
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.09.26 18:24  
DomGilberto:
Yea nice one thanks (all but moving the 1 at the end of "1Yes" like so "Yes1"). How could I go about having a drop down as an extern Yes or No? As opposed to writing it in the box within the parameters? (i.e. not a string but drop-down)
It's an l as in Local   as has been said,  use an enum . . .  I've not used them in mql4 . . .  I have in LabVIEW though 
/
To add comments, please log in or register