Function StrToTime causes error 4051

 

Hi,

the editor in build >600 doesn't like the function StrToTime.

Calling it causes the error 4051. What's wrong??

code is here:

//+------------------------------------------------------------------+
//| test.mq4 |
//+------------------------------------------------------------------+

#property version "1.00"

//--- input parameters
input string TimeClose_="21:45";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---

//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---

}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
datetime xxxxx = StrToTime("21:45"); // makes no difference with TimeClose_ from the input
Print("error: "+GetLastError());
}
//+------------------------------------------------------------------+

The result with every tick:

What's wrong here. Compilation with editor 509 causes no error, of course

 
kla-mue:

Hi,

the editor in build >600 doesn't like the function StrToTime.

Calling it causes the error 4051. What's wrong??

code is here:

<deleted>

Please post your code using the SRC button
 

OK, now I know... next time...

do you have a solution for my problem?

//+------------------------------------------------------------------+
//|                                                         test.mq4 |
//+------------------------------------------------------------------+

#property version   "1.00"

//--- input parameters
input string   TimeClose_="21:45";
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   datetime xxxxx = StrToTime("21:45");
   Print("error: "+GetLastError());
  }
//+------------------------------------------------------------------+
 
kla-mue: OK, now I know... next time...
  1. Next time edit your original post.
  2.    datetime xxxxx = StrToTime("21:45");
       Print("error: "+GetLastError());
    test EURUSD,H1: error: 4051
    Don't call GetLastError() unless you have an error. Is xxxx == 0? Why didn't you print it along with GLE?
  3. Perhaps you should try the new StringToTime
 
kla-mue:

OK, now I know... next time...

do you have a solution for my problem?

It might have been fixed . . . https://www.mql5.com/en/forum/149475 but please report it to the Service Desk anyway.

 
WHRoeder:
  1. Next time edit your original post.
  2. test EURUSD,H1: error: 4051
    Don't call GetLastError() unless you have an error. Is xxxx == 0? Why didn't you print it along with GLE?
  3. Perhaps you should try the new StringToTime



@2: how should i find out if there is an error, if i do not ask GLE?

This code is to find out, why my EA is giving error-messages. No other purpose.


@3: the StringToTime causes the same error :(


Is there an other possibility?

 
kla-mue: @2: how should i find out if there is an error, if i do not ask GLE?

GLE does not tell you IF you have an error. It tells you what the error is WHEN you have one.

GLE returns the last error code. That code is associated with what code? Unknown. Could have been something associated with internal terminal processing or a call from a previous function you called.

Don't call GetLastError() unless you have an error
You have an error if OrderSend returns negative ticket, Time[i] returns zero, or if StringToTime returns zero, etc.
 

StringToTime

The function converts a string containing time or date in "yyyy.mm.dd [hh:mi]" format into datetime type.

datetime StringToTime(
string value // date string
);

Parameters

value

[in] String in " yyyy.mm.dd hh:mi " format.

datetime xxxxx = StringToTime(D'21:45');
 
qjol:
D'21:45'

That is not a string, that is a datetime already (21:45 of the day you compiled the code.)
Read the doc StrToTime()

  datetime var1;
  var1=StrToTime("2003.8.12 17:35");
  var1=StrToTime("17:35");      // returns the current date with the given time
  var1=StrToTime("2003.8.12");  // returns the date with the midnight time of "00:00"
 
but u have to use "yyyy.mm.dd hh:mm" format otherwise u get error 4051
 

PERFECT ! Now its runs without an error =)

It must be the complete date-format!

TNX a lot!!