Reading multiple columns in CSV file using FileSeek.

 

Hi,

I have created CSV file that consists of such structure. I have about 10 000 rows with this type off data.

datetime;string1;string2;string3;string4;string5;

Semicola separetes each other column so that data would be readable.

What I want to achieve is to be able read that data and do some basic analysis. I am using this code

string data1,data2,data3,data4,data5;
   datetime date;
   
    int handle_seek=FileOpen("pair_strenght.csv", FILE_CSV|FILE_READ|FILE_WRITE, ';');
    
    for (int zz=0;zz>=5;zz++)
    {
  if(handle_seek>0)
    {
     FileSeek(handle_seek, 0, SEEK_SET);
    
     FileWrite(handle_seek, date, data1,data2,data3,data4,data5);
     FileClose(handle_seek);
         handle_seek=0;
  
    }
    MessageBox(data1,data2);//message box to check if data exists
    }

How can I read first row for each column and then move to next row. I understand it is about offset. But how can I do that, just insert in cycle that changes the offset from 1 to number_of_rows ? or there is other method?

Thanks :)

 
edgars.rworks:

Hi,

I have created CSV file that consists of such structure. I have about 10 000 rows with this type off data.

Semicola separetes each other column so that data would be readable.

What I want to achieve is to be able read that data and do some basic analysis. I am using this code

How can I read first row for each column and then move to next row. I understand it is about offset. But how can I do that, just insert in cycle that changes the offset from 1 to number_of_rows ? or there is other method?

Thanks :)

You need to seek to the start of the next information you want to read, so once you have read the first row you need to SEEK relative to the current position, SEEK_CUR, the problem with this is knowing how long your strings are, if you know this then you can do it, if not the simplest way is to read the stings, once you have read all those between where you are and where you want to get to you can then read the correct string.

So you will need to read 5 times to get to the next date . . .
 
RaptorUK:
You need to seek to the start of the next information you want to read, so once you have read the first row you need to SEEK relative to the current position, SEEK_CUR, the problem with this is knowing how long your strings are, if you know this then you can do it, if not the simplest way is to read the stings, once you have read all those between where you are and where you want to get to you can then read the correct string.

So you will need to read 5 times to get to the next date . . .


Strings consists of just 3 characters .
Reason: