FileWriteStruct not working

 

Hello,

ArrayPrint shows that array is filled correctly.

File is saved but empty.

If I use FileWrite(…) and add some strings to the file that works. So it must be specific to FileWriteStruct.

Any ideas?


void CTrend::fileWrite()
{
   struct Datefile
   {  double         val1;
      double         val2;
      datetime       time;
   }
   file[];

   ArrayResize(file,1);

   file[0].val1=10.0;
   file[0].val2=100.0;
   file[0].time=TimeCurrent();

   ArrayPrint(file,_Digits,NULL,0,1);

   h=FileOpen("file.csv",FILE_WRITE|FILE_ANSI|FILE_CSV);
   if(h==INVALID_HANDLE)
   {  Alert("Error opening file");
      return;
   }

   FileWriteStruct(h,file[0]);
   FileClose(h);
   Alert("File created");
}
 
 h=FileOpen("file.csv",FILE_WRITE|FILE_ANSI|FILE_CSV);
Perhaps you should read the manual.
The function writes into a bin-file contents of a structure passed as a parameter, starting from the current position of the file pointer.
          File Functions / FileWriteStruct - Reference on algorithmic/automated trading language for MetaTrader 5
 

Ok sometimes you are not seeing the forest for the trees but how useful is it to have the struct as a binary file as I cannot easily view it using Excel, Notpad etc.?!

So how would I write/export a struct to a CSV or text file?

 
algotrader01: So how would I write a struct to a CSV or text file?

Write each member with text functions separated by the file's separator.

 
Thanks for the hint. I got it working using WriteFile + a for loop to iterate over all struct entries. It is then saved as CSV file.