Get a specific value in a cell in excel

 
Hi everyone, the below code is able to write and read values, how can I read a particular value in a cell and not all
   string FileName="test.csv";
FileDelete("test.csv");

int handle = FileOpen ("test.csv", FILE_CSV|FILE_WRITE);
if (handle>0){
   FileWrite(handle,"D1","D2","D3","D4","D5","D6","D7");
   FileWrite(handle,17,21,23,27,30,33,34);
   FileClose(handle);
}

int line2read=2;
int values=7;    
string pivot[2,7];                                    //    [lines,values]
                                                      //    Arrays cannot initialize with vars, only the first dimension can be resized
handle=FileOpen(FileName,FILE_CSV|FILE_READ);     
if(handle>0){                                         
   int line=0;
   string myline;
   while(FileTell(handle)< FileSize(handle)){         //<-- FileIsEnding is buggy and does never return true
      for(int i=0;i<values;i++){                      //    Use FileTell and FileSize instead (https://forum.mql4.com/52640)
         pivot[line,i]=FileReadString(handle);
      }   
      line++;                                         
      if(line==line2read)break;      
   }
}   
FileClose(handle);
for(int j=0;j<values;j++)Print("Value: " + pivot[line2read-1,j]); //-1 as line 2 is at pos 1 in the Array
 
You are creating a CSV file. Read each number on the line line.
 
William Roeder #:
You are creating a CSV file. Read each number on the line line.

Hello William thanks for the reply, how do I read each number? and how can I go to a specific line as with the code I can go to a specific line but it reads all the figures

 

There is no bug in FileIsEnding().

You can't read a specific value in a CSV file (unless it's very strictly formatted with same number of characters on each line), you need to read all up to the value you want.

 
Alain Verleyen #:

There is no bug in FileIsEnding().

You can't read a specific value in a CSV file (unless it's very strictly formatted with same number of characters on each line), you need to read all up to the value you want.

Hello Alain, thanks for the reply, let's say for instance I want to read number 23 on the second line, how do I go about it??

 
Jones John:
Hi everyone, the below code is able to write and read values, how can I read a particular value in a cell and not all

Thanks everyone figured it out I changed the j to the value I needed

for(int j=0;j<values;j++)Print("Value: " + pivot[line2read-1,2-1//changed this j then added -1])