Get Double from LOCAL File

 

hi guys,

i have problem with getting a double value from a local file by using FileReadDouble.

i have stored the "test.csv" in the "MT4_installation_folder\tester\files", the content is simply just "100.11".

i have tried to rename the file to different exension such as "txt" and "dat", but no luck either. there is no issue for the function to find the file, since i dont have any opening file issue/error.

Please help, thanks in advance.

Print(getDouble("text.csv")); --->  print result: the double value is: 0.00000000

double getDouble(string filePath) {
   int handle;
   double value;

   handle=FileOpen(filePath,FILE_BIN|FILE_READ);


   if(handle>0) {
      value=FileReadDouble(handle);
      Print("the double value is: " + value);

      FileClose(handle);
    }else Print("file not founded");
   return (value);
}


 

i have tried FileReadString, it works fine. but seems i have porblem with FileReadDouble. i certainly can use StrToDouble to get around it, but just curiosity how to make the FileReadString works. thanks again.

 
FileReadDouble is used for Binary files. Your file is probably a text file. How was the file created? Was it created using FILE_BIN?
 
ubzen:
FileReadDouble is used for Binary files. Your file is probably a text file. How was the file created? Was it created using FILE_BIN?

it was created in windows manually.
 

Yeah thats why you're having problems. Tested below and it worked.

void start(){
    int Handle=FileOpen(
        WindowExpertName()+".csv",
        FILE_BIN|FILE_READ|FILE_WRITE
    );
    if(Handle<0) Alert("Problem_Opening_File");
    
    FileSeek(Handle,0,SEEK_SET);
    FileWriteDouble(Handle,Open[0],8);
    FileFlush(Handle);
    
    FileSeek(Handle,0,SEEK_SET);
    double Value=FileReadDouble(Handle);
    Print("the double value is: " + Value);
    FileClose(Handle);
}