Download MetaTrader 5

Yes or No "switch"?

To add comments, please log in or register
Dominic Gilbert
1639
Dominic Gilbert  
Whats the simplest way of using an extern string "Yes" or "No" to activate or deactivate a void function?
Simon Gniadkowski
Moderator
18024
Simon Gniadkowski  
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
1639
Dominic Gilbert  
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
7089
Carl Schreiber  
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
Moderator
2336
honest_knave  
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
15566
whroeder1  
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
18024
Simon Gniadkowski  
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