Time disappearance!

 

Guys,

I use the routine below to write a log file of data with a timestamp - worked perfectly for a few hours..then next day all parameters were written to file EXCEPT the timestamp which was ZERO! WTF!!

void WriteLog()
{
 int handle = FileOpen(Symbol()+"_logfile"+".csv",FILE_CSV|FILE_READ|FILE_WRITE,',');
 if(handle>0)
  {
   //write file header
   FileSeek(handle,0,SEEK_SET);
   FileWrite(handle,"Symbol","Time","header1","header2","header3");
   FileSeek(handle,0,SEEK_END);
   FileWrite(handle,Symbol(),TimeToStr(TimeCurrent(),Day()),data1,data2,data3);
   FileClose(handle);            
  }else
      {Alert("Cannot open file "+Symbol()+"_logfile"+".csv");}
return;
}      

What am I doing wrong or is there a ghost in the machine?

thanks

 
sd59:

Guys,

I use the routine below to write a log file of data with a timestamp - worked perfectly for a few hours..then next day all parameters were written to file EXCEPT the timestamp which was ZERO! WTF!!

What am I doing wrong or is there a ghost in the machine?

thanks

... neither of these is the fault in question, but from the definition of FileOpen only a -1 is a fail so in theory ==0 is a possibility, meaning the handle > 0 test may fail.

Also "_logfile" + ".csv" seems strange.

Why not "_logfile.csv" ?

 
string TimeToStr( datetime value, int mode=TIME_DATE|TIME_MINUTES) 
 

The second parameter is wrong in your code. You are using Day().

It is working by accident at first by the looks of it.

 
dabbler:

The second parameter is wrong in your code. You are using Day().

It is working by accident at first by the looks of it.


thanks for the reply - I agree "_logfile" + ".csv" is clunky - probably remnants of changing code. The 'handle' outcome doesn't fail because it writes all other parameters when asked except the time stamp. This was the original output 2012.02.15 21:16:20 but today I noticed it has written a time stamp again (after doing nothing for a day) but only the date and not the time!(2012.02.17) Weird! I haven't changed any code.

Just changed the code to your format and works OK so thanks very much.

 
sd59:


Just changed the code to your format and works OK so thanks very much.


Reason: