read file problem .

 

Hi . I want read data from txt file .

I have a file with name "data.txt" and value inside file is "a"

I wrote this code based on the reference.

int OnInit()
  {
   int file_handle= FileOpen("data.txt",FILE_READ|FILE_ANSI|FILE_TXT);
   if(file_handle!=INVALID_HANDLE)
     {
      while(!FileIsEnding(file_handle))
        {
         string str = FileReadString(file_handle);
         Print(str);
         FileClose(file_handle);
        }
     }
   return(INIT_SUCCEEDED);
  }


The "data.txt" located same folder mql5 file  and the handle value is equal to 1.
But the str value is not printed(The program does not enter the while loop).

Please advise.

Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Running MQL5 Program Properties
  • www.mql5.com
Running MQL5 Program Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
tinivini:

Hi . I want read data from txt file .

I have a file with name "data.txt" and value inside file is "a"

I wrote this code based on the reference.


The "data.txt" located same folder mql5 file  and the handle value is equal to 1.
But the str value is not printed(The program does not enter the while loop).

Please advise.

put the file in the files folder

https://www.mql5.com/en/docs/files

Documentation on MQL5: File Functions
Documentation on MQL5: File Functions
  • www.mql5.com
File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Paul Anscombe #:

put the file in the files folder

worked thanks !
Reason: