Download MetaTrader 5
To add comments, please log in or register
Publish your article and thousands of people all over the world will read it!
Dom_Kissaba
15
Dom_Kissaba 2016.05.16 13:41 
  

Hello friends, I am confused by reading files in CSV .

I created a file and can not write him the ticket orders to be closed in the future, but my problem is time to read these tickets. 

Files

 

I used a function that receives a ticket, and then reads both tickets of the next column, and then sends the three tickets line to another function to close the orders.

 

 
 Example:


 FunctionRead( int ticket )
{

 String A,B,C;
 
 A=IntegerToString(ticket);
 ...
 
 //when the ticket is found, read the two next ticket;
  
 Handle=FileOpen(ArquivoC,FILE_CSV|FILE_READ,";");
     if(Handle<0)
      {Print("Error = ",GetLastError());}
      else
      while(!FileIsEnding(Handle))
           {   
            ...
            //when the ticket is found, read the two next ticket;

            A=StrToInteger(first_column); B=StrToInteger(Second_column); C=StrToInteger(Third_column);
            
            //It is of course that this here is just one example

           }
 Function_Orders_To_Close(A,B,C);

}

for example:

If (ticket == 63) {A = 63, B = 64, C = 65}

If (ticket == 67) {A = 67, B = 68, C = 69}

and so on.

 

 The problem is that the my function only reads the first line of the file.

Someone PLEASE help me?

I've tried several ways, but I can not understand the operation of the pointer when you want to read the CSV data.

(I did not find enough examples to understand the reading files) 

  

Carl Schreiber
5937
Carl Schreiber 2016.05.16 14:53  
Look in the editor's reference and search for FileIsLineEnding() and use the example reading a csv-file
Dom_Kissaba
15
Dom_Kissaba 2016.05.16 15:06  
gooly:
Look in the editor's reference and search for FileIsLineEnding() and use the example reading a csv-file
gooly:
Look in the editor's reference and search for FileIsLineEnding() and use the example reading a csv-file
Thanks for answering gooly.
I've tried it, but do not understand the logic , you could please show me how would a function 
that takes an integer and reads the integer values ​​received over the next two values ​​?
Dom_Kissaba
15
Dom_Kissaba 2016.05.16 15:15  

 My Code;

 

 

void Sumoc(int TKC)
{
     int a,b,c;
     string as,bs,cs;
     
     Print(" Tiket de compra =", TKC);

     HandleSumoC=FileOpen(ArquivoC,FILE_CSV|FILE_READ,";");

     if(HandleSumoC<0)
      {Print("Erro ao tentar abrir o arquivo na função SumoC ",GetLastError());}
      else
      while(!FileIsEnding(HandleSumoC))
      {   
          as    =FileReadString(HandleSumoC);                
          bs    =FileReadString(HandleSumoC);
          cs    =FileReadString(HandleSumoC);
         
          if(FileIsEnding(HandleSumoC)==true)break;
          
        
          if(as==IntegerToString(TKC))
            {
             a=    StrToInteger(as);
             b=    StrToInteger(bs);
             c=    StrToInteger(cs);
            }
          
          Print("a b c  e TKC=========================================================== ",a," ", b, " ",c," e TKC ",TKC);

          close_orders(a,b,c);
           
          FileClose(HandleSumoC);
          
      }  
}
Demos Stogios
184
Demos Stogios 2016.05.16 21:28  
Dom_Kissaba:

 My Code;

 FileClose(HandleSumoC);

FileClose() might be the culprit here; you might put it inside (or elsewhere)

if(FileIsEnding(HandleSumoC) ) /* please notice i am not puttin ==true on purpose */

 

or the file will close the very first time while is executed 

Also, while i can not be sure, it looks to me that you actually want to put all following lines inside if

          if(as==IntegerToString(TKC))
            {
             a=    StrToInteger(as);
             b=    StrToInteger(bs);
             c=    StrToInteger(cs);
          /*  curly } not here */
          
          Print("a b c  e TKC=========================================================== ",a," ", b, " ",c," e TKC ",TKC);

          close_orders(a,b,c);

          } /* maybe here ( a guess ) */ 

 

 best regards

Dom_Kissaba
15
Dom_Kissaba 2016.05.17 03:15  
forgiveness, really was wrong, I had changed the code later

It was so!

 table for reading.

DB 

 

Code for read the table. 

void Sumov(int TKC)
{
     int a,b,c; 
     string as,bs,cs;
     
     Print(" Primeiro Ticket ", TKC);                                          //first ticket

     HandleSumoV=FileOpen(ArquivoV,FILE_CSV|FILE_READ,";");
     if(HandleSumoV<0)
      {Print("Erro ao tentar abrir o arquivo na função SumoV ",GetLastError());}
      else
      while(!FileIsEnding(HandleSumoC))
      {   
          as    =FileReadString(HandleSumoV);                                  
          bs    =FileReadString(HandleSumoV);
          cs    =FileReadString(HandleSumoV);
         
          if(as==IntegerToString(TKC))                                        // if first ticket read
            {
             a=    StrToInteger(as);                                          //a=first ticket
             b=    StrToInteger(bs);                                          //b=second Ticket
             c=    StrToInteger(cs);                                          //c=third ticket
             FileClose(HandleSumoC);
             Print(" ordens que devem ser fechadas ", a," ",b," ",c);         //orders to close
            }
            
          CLOSE_ORDERS(a,b,c);                                                //function that takes the orders to be closed
          
if(FileIsEnding(HandleSumoV)==true)break;
           
      } 
          FileClose(HandleSumoV);                                             
          FileFlush(HandleSumoV);
}

 

 The function works in the first loops but then begins to error.

printed numbers.

           a              b              c            

1 22 23
2 32 33
35 36 37
31 0 0
0 0 0
0 0 0

 

 

Carl Schreiber
5937
Carl Schreiber 2016.05.17 07:44  
If it is an indicator put the relevant code in a script - otherwise start the debugger right away and control the variables and _LastError and either mark various lines by F9 or place DebugBreak(); after relevant code...
Dom_Kissaba
15
Dom_Kissaba 2016.05.17 08:25  

Very thanks for answering Gooly. I will try this

/
To add comments, please log in or register