how to input data in while loop

 
Hi,
I am trying to get data from user's input then process the data if they are already correct. This is my code:

#property show_inputs
extern double Range, Lot; // many more

int start()
{
....
....
ok = false;
while (!ok) {
// check Range, Lot , etc
// if it is not ok, ask to input the data again
// how to do it???

}

}


Thanks
suheimi
 
If you are coding an EA, you can use MessageBox() to inform user and get their input.

int start(){
   ...
   ...
   ...
   while(!OK){
      MessageBox(..., ... );
      Sleep(5000);
      init();
      start();
   }
   ...
   ...
   return(0);
}
  
 
Thanks Phy,
I tried as you suggested. However, the code keep showing the MsgBox. What's wrong?



#property copyright "Copyright © 2008."
#property link ""
#include <WinUser32.mqh>
#property show_inputs


extern double Range=10;
extern double Lot=1;

int init()
{
return(0);
}

int deinit()
{
return(0);
}

int start()
{
bool ok=false;
string str;

str = "Range = \t"+ Range+"\n"+
"Lot = \t"+Lot;

while (!ok){
int handle=MessageBox(str+"\nCONTINUE ?", "Please Validate Your Data !", MB_YESNO|MB_ICONQUESTION);
if(handle==IDNO){
Print("Reenter data...");

Sleep(5000);
init();
start();
} else ok=true;

} //while

return(0);
}






If you are coding an EA, you can use MessageBox() to inform user and get their input.

int start(){
   ...
   ...
   ...
   while(!OK){
      MessageBox(..., ... );
      Sleep(5000);
      init();
      start();
   }
   ...
   ...
   return(0);
}
  


 
Look at your logic.

Your code starts by setting OK = false

Then if OK is false you call your MessageBox. Every tick.

Put the data verification (and decide if OK should be true) before calling MB (due to OK being false)
 

Look at your logic.

Your code starts by setting OK = false

Then if OK is false you call your MessageBox. Every tick.

Put the data verification (and decide if OK should be true) before calling MB (due to OK being false)


Thanks Phy, But I stil don't know how to do it:
This is the code:


#property copyright "Copyright © 2008."
#property link ""
#include <WinUser32.mqh>
#property show_inputs

extern double Lot=0;

int init() {
return(0);
}

int deinit() {
return(0);
}

int start()
{
bool ok=false;
string str = "Lot = \t"+Lot;

while (!ok){

if (Lot <=0) {
int handle=MessageBox(str+"\nPlease Reenter", "Warning",
MB_OKCANCEL|MB_ICONWARNING);

Sleep(5000);
init();
start();

//---
// can user change the value of Lot here?
//---
}
else ok=true;

} //while

// Lot already > 0
Alert("Start trading with positive Lot value ...", Lot);

return(0);
}
 
hi...

try to use Global Variables....