Reading from TXT file - page 2

 
lippmaje:

and when you add this to the bottom:

Result attached..weird... 

Files:
result.gif  14 kb
 
Check if you are really opening the right file. Change the file name to be sure.
 
Victor Carozo:

Dear

Here the code updated as suggested. 


I attached the .txt file for conference and compile results. I still not hold the data from ''sample.txt'' in the ''trade'' structure, anyone has another suggestion?

Why do u code 

short delimiter=';';

when ur sample.txt file is obviously delimited by ','?

Also, you need to re-save your sample.txt in unicode encoding (windows Notepad can do that).
 

Replace with the code. then it is ok

   short delimiter=',';
   int fileHandle = FileOpen("Sample.txt",FILE_ANSI|FILE_READ|FILE_CSV,delimiter);
 
Oh yes! using the FILE_ANSI flag should achieve the same effect as re-saving the file in unicode.
 
Seng Joo Thio:
Oh yes! using the FILE_ANSI flag should achieve the same effect as re-saving the file in unicode.

Thanks !! Finally solved. Here the correct code.


//+------------------------------------------------------------------+
//|                                                      Stategy.mq5 |
//|                                                    Victor Carozo |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Victor Carozo"
#property link      "https://www.mql5.com"

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
  struct Table
  {   
      int line; 
      datetime date;
      string symbol;
      double price;
     
  };
   
   Table table[];
   
   int i=0;
   
   short delimiter=',';
   int fileHandle = FileOpen("Sample.txt",FILE_READ|FILE_ANSI,delimiter);
   
   if(fileHandle==INVALID_HANDLE) Alert("could not open file, error: "+(string)GetLastError()); 

   if(fileHandle!=INVALID_HANDLE) 
    {
     while(FileIsEnding(fileHandle) == false)
       {
   
  
        ArrayResize(table,ArraySize(table) +1 );     
        table[i].line = (int) FileReadNumber(fileHandle);
        table[i].date = FileReadDatetime(fileHandle);
        table[i].symbol = FileReadString(fileHandle);
        table[i].price = FileReadNumber(fileHandle);
        
     
       i++;
      
      }
     
     FileClose(fileHandle);   
       
    }
    Print("table size: ",ArraySize(table));
    for(i=0; i<ArraySize(table); i++) Print(table[i].line," ",table[i].date," ",table[i].symbol," ",table[i].price);

    

}
//+----------------------------------------------------------------+