Download MetaTrader 5

External File Reading

To add comments, please log in or register
No time to learn MQL5? Order your application from a developer!
proto
16
proto 2013.12.20 15:01 

Can anyone advise?

Am trying ot read an external file which I have placed in the C:/Program Files/MetaTrader 4/experts/files folder.

However the erro message on the compiler says number 4 invalid number and refers to the number 4 of the MetaTrader 4 sub-folder.


How can this be overcome as I must not change the sub-folder MetaTrader 4.

Is there any wording in the program that I can by pass this error so that the file can be read from the C:/path file?

Note: the external file has to be in the MetaTrader 4/experts file to run.

Any advice is welcome

Thanks

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.12.20 15:11  
Proto:

Can anyone advise?

Am trying ot read an external file which I have placed in the C:/Program Files/MetaTrader 4/experts/files folder.

However the erro message on the compiler says number 4 invalid number and refers to the number 4 of the MetaTrader 4 sub-folder.


How can this be overcome as I must not change the sub-folder MetaTrader 4.

Please show your code and please use the SRC button to do so.

Are you using the whole file and path in your FileOpen() ? you only need the filename . . . click the link <----
whroeder1
14519
whroeder1 2013.12.20 16:28  
  1. Don't install in \program files* (Avoid the UAC problems)
  2. The call to open the file is the "filename" or "subdirectory\\filename" You can only read from "C:\\Program Files\\MetaTrader 4\\experts\\files\\" (or tester\files) don't add the path.
  3. The filename is a string, you don't have it quoted thus the error about 4
  4. There are no mind readers here. Always post your code (using SRC)
proto
16
proto 2013.12.20 16:39  
If I put just the Book1 File in the exerts/file folder, then it doesn't show that it can find it and there are many more error messages
proto
16
proto 2013.12.20 16:45  
//+------------------------------------------------------------------+
//|                                                         4 |
//|                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_minimum 0.0
#property indicator_maximum 0.1

/*---------------------------------------------------------------------

   Declaration of Properties
   
-----------------------------------------------------------------------
*/
 
    int A, B, C, D, E, F;    //Variable declaration in External File
    //int Handle;,                                                          //File descriptor
    int Stl;,                                                             //Style of Vertical Line
    //string Str="some string";
    string A=FxPro - MetaTrader 4
    string File_Name=C:\Program Files (x86)\FxPro - MetaTrader 4\("Book1.xlsx",';');    
    int Handle=FileOpen(File_Name,FILE_BIN,FILE_READ,FILE_WRITE);
    //string Object="Obj_Name";,                                          
    //Instr                                                               
    //string One,Two                                                      
    //string Text,                                                        
    //Str_DtTm;                                                           
    datetime Dat_DtTm;                                                    
   
    //Color Col;                                                          //Colour of Vertical Line
              
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+

int init()
Handle=FileOpen (File_Name,FILE_CSV|FILE_READ|FILE_WRITE,";");            //Opening File
if (Handle<0)                                                             
   {
      if (GetLastError()==4130                                            
                      Alert ("No File Found", File_Name);                 
                    else                                                  
                        Alert ("Error in Finding File",File_Name);        
                                 PlaySound ("Bzzzr.wav");              
   return;                                                                
   }
//--------------------------------------------------------------------
  //}
//--------------------------------------------------------------------

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }

//----
proto
16
proto 2013.12.20 16:57  

I'd like the file to be opened, Read and written to.

Any advice would be welcomed.

Thanks so far

proto
16
proto 2013.12.20 17:27  

Can anyone tell me how to prevent these errors?

'{' - expression on global scope not allowed

'Handle' - semicolon expected

'File_Name' - expression on global scope not allowed etc in the error messages on the above program?




Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.12.20 17:31  
Proto:

Can anyone tell me how to prevent these errors?

'{' - expression on global scope not allowed

'Handle' - semicolon expected

'File_Name' - expression on global scope not allowed etc in the error messages on the above program?

This is an expression and it has to go into a function . . .

int Handle=FileOpen(File_Name,FILE_BIN,FILE_READ,FILE_WRITE);

no semi colon . . .

string A=FxPro - MetaTrader 4

If you are trying to run this in the Strategy Tester then your file has to go into /tester/files/ not /experts/files

To add comments, please log in or register