Download MetaTrader 5
To add comments, please log in or register
MQL5 Cloud Network speeds up calculations. Try it!
Jerry Spence
216
Jerry Spence 2010.02.07 01:59 

I have:

bool   MyVar = false;

When I try and display a comment:

Comment ("MyVar: " + MyVar);

I get implicit conversion from 'number' to 'string' warning when compiling.

In MT4 it would compile OK and print a 'one' or 'zero' corresponding to true or false. How do we now display booleans in a Comment?

-Jerry

Paul
784
Paul 2010.02.07 02:22  
netconuk posted  :

I have:

bool   MyVar = false;

When I try and display a comment:

Comment ("MyVar: " + MyVar);

I get implicit conversion from 'number' to 'string' warning when compiling.

In MT4 it would compile OK and print a 'one' or 'zero' corresponding to true or false. How do we now display booleans in a Comment?

-Jerry

This is due to more stringent type-checking in MQL5, which has many benefits of picking up coding errors.

 If you want to eliminate the warnings, you need to explicitly type-cast the variable, as in

Comment ("MyVar: " + (string)MyVar);

Or use the multiple parameter feature of Comment() 

Comment ("MyVar: ",MyVar);

 Or perhaps better still

Comment ("MyVar: ",BoolToString(MyVar));



string BoolToString(bool b)
{
   if (b) return("true");
   else return("false");
}
 

 Paul

http://paulsfxrandomwalk.blogspot.com/ 

Regularly emailing the status of an account
  • 2012.06.14
  • Paul
  • paulsfxrandomwalk.blogspot.com
Prompted by a query, I thought I'd post a useful little utility that I have used for ages which emails the status of the account every hour.  After lengthy deliberation I decided to call it .... EmailStatus.  With only a small modification it could be used to log the status to a file, and the time...
Jerry Spence
216
Jerry Spence 2010.02.08 01:32  
string BoolToString(bool b)
{
   if (b) return("true");
   else return("false");
}

Thanks Paul. That's a great Help.Actually BoolToString would be a useful command to be included in MT5.

-Jerry

Paul
784
Paul 2010.02.08 02:58  

 Glad you like BoolToString - attached is a stack of string utilities  :)

 From time to time this will need updating as MetaQuotes adds extra error codes.

Paul

http://paulsfxrandomwalk.blogspot.com/ 

Regularly emailing the status of an account
  • 2012.06.14
  • Paul
  • paulsfxrandomwalk.blogspot.com
Prompted by a query, I thought I'd post a useful little utility that I have used for ages which emails the status of the account every hour.  After lengthy deliberation I decided to call it .... EmailStatus.  With only a small modification it could be used to log the status to a file, and the time...
Files:
/
To add comments, please log in or register