La funzione StrToTime causa l'errore 4051

 

Ciao,

l'editor nella build >600 non ama la funzione StrToTime.

Chiamarla causa l'errore 4051. Cosa c'è che non va?

Il codice è qui:

//+------------------------------------------------------------------+
//| 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());
}
//+------------------------------------------------------------------+

Il risultato con ogni spunta:

Cosa c'è di sbagliato qui. La compilazione con l'editor 509 non causa alcun errore, ovviamente

 
kla-mue:

Ciao,

l'editor nella build >600 non ama la funzione StrToTime.

Chiamarla causa l'errore 4051. Cosa c'è che non va?

Il codice è qui:

<cancellato>.

Per favore, pubblica il tuo codice usando il pulsante SRC
 

OK, ora lo so... la prossima volta...

avete una soluzione per il mio problema?

//+------------------------------------------------------------------+
//|                                                         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, ora lo so... la prossima volta...
  1. La prossima volta modifica il tuo post originale.
  2.    datetime xxxxx = StrToTime("21:45");
       Print("error: "+GetLastError());
    test EURUSD,H1: errore: 4051
    Non chiamare GetLastError() a meno che tu non abbia un errore. xxxx == 0? Perché non l'hai stampato insieme a GLE?
  3. Forse dovresti provare il nuovo StringToTime
 
kla-mue:

OK, ora lo so... la prossima volta...

avete una soluzione per il mio problema?

Potrebbe essere stato risolto . . https://www. mql5.com/en/forum/149475 ma per favore segnalalo comunque al Service Desk.

 
WHRoeder:
  1. La prossima volta modifica il tuo post originale.
  2. test EURUSD,H1: errore: 4051
    Non chiamare GetLastError() a meno che tu non abbia un errore. È xxxx == 0? Perché non l'hai stampato insieme a GLE?
  3. Forse dovresti provare il nuovo StringToTime



@2: come faccio a scoprire se c'è un errore, se non chiedo a GLE?

Questo codice è per scoprire perché il mio EA sta dando messaggi di errore. Nessun altro scopo.


@3: lo StringToTime causa lo stesso errore :(


C'è un'altra possibilità?

 
kla-mue: @2: come faccio a sapere se c'è un errore, se non lo chiedo a GLE?

GLE non ti dice SE hai un errore. Ti dice qual è l'errore QUANDO ne hai uno.

GLE restituisce l'ultimo codice di errore. Quel codice è associato a quale codice? Sconosciuto. Potrebbe essere stato qualcosa associato all'elaborazione interna del terminale o una chiamata da una funzione precedente che avete chiamato.

Don't call GetLastError() unless you have an error
Hai un errore se OrderSend restituisce un ticket negativo, Time[i] restituisce zero, o se StringToTime restituisce zero, ecc.
 

StringToTime

La funzione converte una stringa contenente tempo o data nel formato "yyyy.mm.dd [hh:mi]" nel tipo datetime.

datetime StringToTime(
string value // date string
);

Parametri

valore

[Stringa nel formato " yyyy.mm.dd hh:mi ".

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

Questa non è una stringa, è già un datetime (21:45 del giorno in cui avete compilato il codice).
Leggete il documento StrToTime()

  datetime var1; var1=StrToTime("2003.8.12 17:35"); var1=StrToTime("17:35"); // restituisce la data attuale con l'ora data var1=StrToTime("2003.8.12"); // restituisce la data con l'ora di mezzanotte "00:00"
 
ma devi usare il formato "yyyy.mm.dd hh:mm" altrimenti ottieni l'errore 4051
 

PERFETTO! Ora funziona senza un errore =)

Deve essere il formato data completo!

TNX un sacco!