Download MetaTrader 5
To add comments, please log in or register
What is MetaQuotes ID? Find that out from the article!
strontiumDog
263
strontiumDog 2014.08.08 22:40 

Hello

I have a file which I wrote with Notepad which contains:

1406718000

1406719800

so should have Win line endings.


This code:

void readInTradeEvents() {
    i = 0;
    int fh=FileOpen("eventdates.txt",FILE_READ);
    if(fh != INVALID_HANDLE) {
        ArrayResize(dates, 0);      // empty and refill
        ArrayResize(dates, ArraySize(dates)+1);
        FileSeek(fh,0,SEEK_SET);
        while(!FileIsEnding(fh)) {
            dates[i] = StringToInteger(FileReadString(fh,10));
            PrintFormat(dates[i]);
            i += 1;
        }
        FileClose(fh);
        Print("Read ",ArraySize(dates)," dates into dates array");
        SendNotification(StringConcatenate("EA ",tradeNote," [",Symbol(),"]: Reread eventdates.txt"));
    }
    else Print("Read of event dates file failed. Error: ",GetLastError());    
}


Parses the file and the EA outputs only the first entry (which is the second line in the log once the second line is output too):

0

1406718000


What am I doing wrong?  This was working not so long ago.  I've tried a number of different combinations and none work.  The EA only reports that it has read in one entry only.

Keith Watford
Moderator
8023
Keith Watford 2014.08.08 23:41  
You don't resize the array dates in your while loop
Алексей Тарабанов
7220
Алексей Тарабанов 2014.08.08 23:43  
int fh=FileOpen("eventdates.txt",FILE_READ|file_write);
strontiumDog
263
strontiumDog 2014.08.12 08:32  
GumRai:
You don't resize the array dates in your while loop

GumRai, exactrly right - thanks.
/
To add comments, please log in or register