FileOpen error 5011

To add comments, please log in or register
Essam Daoud
1129
Essam Daoud  

Hi

This code needs to open/create a file to write in, so that the content of the file will ONLY have what is being written by this code.

GetLastError() is reporting 5011. Could some one please show why and how to fix it?

The docs says File must be opened with FILE_BIN flag, but I want to write text, so why mql4 not allowing it?

But when I do that, it gives error 5008.

Thanks

  double spread = MarketInfo(Symbol(),MODE_SPREAD)/10;
  int fH = FileOpen("//spread//"+Symbol()+".txt", FILE_WRITE|FILE_TXT); // line 1
  //int fH = FileOpen("//spread//"+Symbol()+".txt", FILE_BIN); // line 2
  if(FileWriteDouble(fH ,spread) == 0){
    Print(GetLastError());      //<<<<<<<<<<<<<<<<<<< ERROR 5011 with line 1, OR 5008 with line 2 instead
    Print("**************************");
  }
  FileClose(fH);
William Roeder
20228
William Roeder  
  1. samjesse: The docs says File must be opened with FILE_BIN flag, but I want to write text, so why mql4 not allowing it?
    Because the function you are trying to use is only for binary files. Just FileWrite it.

  2. samjesse: But when I do that, it gives error 5008.
    Do you really expect an answer? We can't see your broken code. There are no mind readers here and our crystal balls are cracked.
Essam Daoud
1129
Essam Daoud  
whroeder1:
  1. Because the function you are trying to use is only for binary files. Just FileWrite it.

  2. Do you really expect an answer? We can't see your broken code. There are no mind readers here and our crystal balls are cracked.


Thanks for the hint of using

if(FileWrite(fH ,spread) == 0){

instead of:

if(FileWriteDouble(fH ,spread) == 0){
To add comments, please log in or register