Download MetaTrader 5

Reading Writing to External File

To add comments, please log in or register
ppapp
39
ppapp  

Can anyone pls advise

I am trying to run this basic short MQL program to read/write to external file and have reduced errors but can't get further.

Can anyone help in debugging this?

//+------------------------------------------------------------------+
//|                                                          |
//|                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#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
   
-----------------------------------------------------------------------
*/

//Line 20
 
    int A, B, C, D, E, ;    //Variable declaration in External File
    int Handle
  
                                           
// int Stl;,                                                             //Style of Vertical Line
    //string Str="some string";

   {
   int Handle
   
    //Handle=FileOpen(File_Name,FILE_CSV|FILE_READ,";");
    Handle=FileOpen(File_Name,FILE_BIN,FILE_READ,FILE_WRITE,";");             // File opening
    //string Object="Obj_Name";,                                          //Name of Object
    //Instr                                                               //Name of Currency
    //string One,Two                                                      //1st & 2nd name of Instr.
    //string Text,                                                        //Text of event description
    //Str_DtTm;                                                           //Start of Date and Time (Line)
    }
    
    
    datetime Dat_DtTm;                                                    //Date and Time of event
   
    //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)                                                             //Fail of opening File
   {
      if (GetLastError()==4130                                            //If cannot find File
                      Alert ("No File Found", File_Name);               // Inform User
                    else                                                  //In case of other error
                        Alert ("Error in Finding File",File_Name);        //Inform User of error
                                 PlaySound ("Bzzzr.wav");                 //Play Alert Sound
   return();                                                                //Exit Start ()
   }
//-----------------------------------------------------------------------If File cannot be found Error return


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

//----
ERRORS

Compiling 'External File Open read write.mq4'...        
';' - variable expected                                 \External File Open read write.mq4 (23, 24)
'{' - comma or semicolon expected                       \External File Open read write.mq4 (30, 4)
'Handle' - comma or semicolon expected                  \External File Open read write.mq4 (34, 5)
'File_Name' - expression on global scope not allowed    \External File Open read write.mq4 (34, 21)
'File_Name' - variable not defined                      \External File Open read write.mq4 (34, 21)
'}' - unbalanced parentheses                            \External File Open read write.mq4 (40, 5)
5 error(s), 1 warning(s)        
ppapp
39
ppapp  

Added the line to find the External File Name and even more errors

Can anyone help de-bug these.


//+------------------------------------------------------------------+
//|                                                          |
//|                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#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
   
-----------------------------------------------------------------------
*/
//Line 20
 
    int A, B, C, D, E;    //Variable declaration in External File
    int Handle
   
                                           
// int Stl;,                                                             //Style of Vertical Line
    //string Str="some string";
string File_Name=("Book1.xlsx");    //External File Name

//line 30
   {
   int Handle
  
    //Handle=FileOpen(File_Name,FILE_CSV|FILE_READ,";");
    Handle=FileOpen(File_Name,FILE_BIN,FILE_READ,FILE_WRITE,";");             // File opening
    //string Object="Obj_Name";,                                          //Name of Object
    //Instr                                                               //Name of Currency
    //string One,Two                                                      //1st & 2nd name of Instr.
    //string Text,                                                        //Text of event description
    //Str_DtTm;                                                           //Start of Date and Time (Line)
    }
    
    
    datetime Dat_DtTm;                                                    //Date and Time of event
   
    //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)                                                             //Fail of opening File
   {
      if (GetLastError()==4130                                            //If cannot find File
                      Alert ("No File Found", File_Name);               // Inform User
                    else                                                  //In case of other error
                        Alert ("Error in Finding File",File_Name);        //Inform User of error
                                 PlaySound ("Bzzzr.wav");                 //Play Alert Sound
   return();                                                                //Exit Start ()
   }
//-----------------------------------------------------------------------If File cannot be found Error return


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

//----




ERRORS

'Handle' - variable not defined                                   \External File Open read write.mq4 (53, 1)
'File_Name' - expression on global scope not allowed              \External File Open read write.mq4 (53, 18)
'File_Name' - variable not defined                                \External File Open read write.mq4 (53, 18)
'Handle' - expression on global scope not allowed                 \External File Open read write.mq4 (54, 5)
'Handle' - variable not defined                                   \External File Open read write.mq4 (54, 5)
'File_Name' - variable not defined                                \External File Open read write.mq4 (57, 46)
'File_Name' - variable not defined                                \External File Open read write.mq4 (59, 55)
10 error(s), 5 warning(s)       
whroeder1
15727
whroeder1  
Please edit your first post, use SRC for the code (like you did in the second.)

';' - variable expected
No token between comma and semicolon.
'{' - comma or semicolon expected
No semicolon.
    int A, B, C, D, E, ;    //Variable declaration in External File
    int Handle
'Handle' - comma or semicolon expected
Start of function definition [int init()] but no braces.
int init()
Handle=FileOpen (File_Name,FILE_CSV|FILE_READ|FILE_WRITE,";"); //Opening File
Code outside of function.
//line 30
   {
ppapp
39
ppapp  

I have managed to re-organise the code and de-bug to one error message which reads

Compiling 'FILE READ.mq4'...

'(' - function definition unexpected C:\Users\P\Documents\mql4\Draft Indicator Folder\FILE READ.mq4 (55, 11)

1 error(s), 0 warning(s)

Can someone help to get rid of all errors?


//+------------------------------------------------------------------+
//|                                                          |
//|                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_minimum 0.0
#property indicator_maximum 0.1
//int File_Name
/*---------------------------------------------------------------------

   Declaration of Properties
   
-----------------------------------------------------------------------
*/
int init()
{
        return (0);

}
//Line 20
int start()

{
    
    ;int NewsDateTime, Currency, Description, EventAlert, EventValue, WriteResult;               //Variable declaration in External File
    int Handle, //nbre=0;//,sens=2,ticket=3333;
    File_Name="Book1", sens=2, ticket=3333;                                
    Handle=FileOpen(File_Name,FILE_BIN,FILE_READ,FILE_WRITE,";");                                // File opening  
    
          if(Handle<0)                                                                           //File Opening fails
 
   {
   
             if (GetLastError()==4130                                                             //If cannot find File
                             Alert ("No File Found", File_Name);                                  // Inform User
                           else                                                                   //In case of other error
                               Alert ("Error in Finding File",File_Name);                         //Inform User of error
                                        PlaySound ("Bzzzr.wav");                                  //Play Alert Sound
                                        
           datetime Dat_DtTm;                                                                     //Date and Time of event
   
        return(0);                                                                                //Exit Start ()
  
   }


//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----

   
//----
   return(0);
  }
//+--------
                                             
             

I have tried balancing the opening and closing parentheses yet there is still one erro message.

Can someone pls help with this code to get rid off all error messages?

Simon Gniadkowski
Moderator
18021
Simon Gniadkowski  
ProPap:

I have managed to re-organise the code and de-bug to one error message which reads

Compiling 'FILE READ.mq4'...

'(' - function definition unexpected C:\Users\P\Documents\mql4\Draft Indicator Folder\FILE READ.mq4 (55, 11)

1 error(s), 0 warning(s)

Can someone help to get rid of all errors?


I have tried balancing the opening and closing parentheses yet there is still one erro message.

Can someone pls help with this code to get rid off all error messages?

Why the semi colon at the start of the line ?

 ;  int NewsDateTime, Currency, Description, EventAlert, EventValue, WriteResult;               //Variable declaration in External File

File_Name is supposed to a string, you have made it an int . .

    int Handle, //nbre=0;//,sens=2,ticket=3333;    // no semi colon at the end of this line, you commented it out . . .
    File_Name = "Book1", sens=2, ticket=3333;     // so File_Name is an int
To add comments, please log in or register