Error

 

Good afternoon!

I got this code from the MT5 documentation examples:

=========================================================================
bool ReadFileToArray( string NomeTXT, string & Linhas[])

   {
       ResetLastError ();
       int h = FileOpen ( NomeTXT, FILE_READ | FILE_ANSI | FILE_TXT );
       if (h == INVALID_HANDLE )
{
int ErrNum = GetLastError ();
printf ( "Erro ao abrir o arquivo %s # %i" , NomeTXT, ErrNum);
     return ( false );
}
       int cnt = 0 ; 
       while (! FileIsEnding (h))
         {
             string txt = FileReadString (h); 
             StringTrimLeft (txt); 
             StringTrimRight (txt);
             if (txt != "" )
               { 
                   if (cnt >= ArraySize (Linhas))
                     { 
                         ArrayResize (Linhas, ArraySize (Linhas) + 1024 ); 
                     }
                  Linhas[cnt] = txt; 
                  cnt++; 
               }
         }
       ArrayResize (Linhas, cnt);
       FileClose (h);
       return ( true );
   }

===============================================================================

fiz a chamada dele numa outra função:

       if (!ReadFileToArray( "ListagemVolumes.txt" , Lista))
         {
             Alert ( "EA ID: " + IntegerToString (EA_Magic) + ". Erro ao ler arquivo de texto! (" , __FUNCTION__ , ")" );
             return ( false );
         }

The problem is that regardless of the text placed in the file name, error 5004 (ERR_CANNOT_OPEN_FILE) always returns.

The file is in the Files folder within the MT5 folder.
I've tried "\\ Files \ ListagemVolumes.txt", "\ Files \ ListagemVolumes.txt", "Files \ ListagemVolumes.txt", "Files / ListagemVolumes.txt" and "ListagemVolumes.txt"

Where's the error?


Thank you for your help!

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
  • www.mql5.com
The CLR_NONE constant is used to outline the absence of color, it means that the graphical object or graphical series of an indicator will not be plotted. This constant was not included into the Web-color constants list, but it can be applied everywhere where the color arguments are required. The EMPTY_VALUE constant usually corresponds to the...
 
  1. If it's in the files folder, not a sub-folder of files, you only use the name.ext. Make sure that is exactly where it is, by opening Files → Open Data Folder, and has no typos.

  2.                    if (cnt >= ArraySize (Linhas))
                         { 
                             ArrayResize (Linhas, ArraySize (Linhas) + 1024 ); 
    You are resizing the array to its current size, not cnt+1.