FileWriteStruct Issue

To add comments, please log in or register
Stanislav Ivanov
5107
Stanislav Ivanov  

Hi guys, i am using a struct to save DoM data into a file(TXT), but it has a problem, it is for passing a struct object , not a link or a reference. I tried doing that but didnt work.

I am sending the code if someone can help.

   Datefile file;
   file.symb=_Symbol;
   file.ask_volume=Ask;
   file.bid_volume=Bid;
   file.tm=time;
   int file_handle=FileOpen(file_name,FILE_WRITE|FILE_READ|FILE_BIN|FILE_COMMON);//|FILE_READ|FILE_TXT|FILE_ANSI,'\t',CP_ACP
   if(file_handle!=INVALID_HANDLE)
     {
      PrintFormat("%s file is available for writing",file_name);
      PrintFormat("File path: %s\\Files\\",TerminalInfoString(TERMINAL_DATA_PATH));
      //--- first, write the number of signals
      FileSeek(file_handle,0,SEEK_END);
      uint write=FileWriteStruct(file_handle,file);
      Print("Write ",write," errro ",GetLastError());
      //--- close the file
      FileClose(file_handle);
      PrintFormat("Data is written, %s file is closed",file_name);
     }
   else
      PrintFormat("Failed to open %s file, Error code = %d",file_name,GetLastError());
  }
Mehrdad Jeddi
28618
Mehrdad Jeddi  

Hi,

Your code is incomplete.

So if you check the documentation carefully,it explained as "The structure should not contain strings, dynamic arrays or virtual functions" at " FileWriteStruct" function section.

So it means,your structure should not contain string data type in its variable stack,

So your structure should be like below:

struct Datefile
  {
   //string            symb;
   double            ask_volume;
   double            bid_volume;
   datetime          tm;
  };

And the :

//file.symb=_Symbol;
Should be removed,
Stanislav Ivanov
5107
Stanislav Ivanov  
Mehrdad Jeddi:

Hi,

Your code is incomplete.

So if you check the documentation carefully,it explained as "The structure should not contain strings, dynamic arrays or virtual functions" at " FileWriteStruct" function section.

So it means,your structure should not contain string data type in its variable stack,

So your structure should be like below:

And the :

Should be removed,

Thanks for your help

Mehrdad Jeddi
28618
Mehrdad Jeddi  
Stanislav Ivanov:

Thanks for your help

You're welcome,

To add comments, please log in or register