Last Line in File - page 2

 
BenLinus:

Just found out there is a bug in my original function and I couldn't track it down. It sometimes returns things that are not even in the file.

I wanted to try simpler code but it didn't work out as well :( .

shouldn't this work:

According to the doc on FileReadString you have to specify the length of the string you want to read.

 
szgy74:

how do you open the file? what is the FileOpen() code?




int init()
{
        TotalSymbols = StoreSymbols(SymbolArray);

        for(int i =0; i< TotalSymbols; i++){                    //for each symbol


                for(int PeriodIndex=0; PeriodIndex< ArraySize(Periods) ; PeriodIndex++ ){       

                        string s[6] = {"1m ", "5m ","15m","1h","1d","1w"};
                        s[PeriodIndex]= SymbolArray[i] + " " + s[PeriodIndex];

                        FileNames[PeriodIndex] = "CHART DATA - " + AccountCompany()+ "\\ " + StringSubstr(SymbolArray[i],0,6) + FileNameEnds[PeriodIndex] ;      


                        int Handle  = FileOpen(FileNames[PeriodIndex] , FILE_CSV|FILE_READ|FILE_WRITE, "\t");
                        string LastTickString = GetLastLine(Handle);

                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                        ///DEBUGGING

                        if (StringLen(LastTickString)<44) {     
                                Print(s[PeriodIndex], ": LastTickString is too short. LastTickString = " ,  LastTickString );
                                //       return(1);
                        }
                        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                        //                      Print(s[PeriodIndex], ": LastTickstring= ",LastTickString);

                        FileClose(Handle);
                }
        }  
        return(0);
}         

I wrote this code just to test the function.

 
szgy74:

According to the doc on FileReadString you have to specify the length of the string you want to read.



FileReadString( int handle, int length=0)


Also, the doc has an example with no length specified. From what I've tried, it just reads till the end of line.

 
Actually, I just retested my first code with only one file. It seems to work with no issues. But, when use it for all my files like above, it starts to misbehave.