hi can some body tell me why my file writing code override the existing values?
You Open the File, you write to it, then you close it. Then you repeat this . . . read the documentation and then explain what you think your code should be doing . . .
int handle; handle=FileOpen("cur.csv", FILE_CSV|FILE_WRITE, ';'); if(handle<1) { return(false); } else{ FileSeek(handle, 0, SEEK_END); FileWrite(handle,"curdailyopen",curdailyopen,"previousdailyopen",previousdailymedian,"curweeklyopen",curweeklyopen,"previousweeklymedian", previousweeklymedian,"curmonthlyopen",curmonthlyopen,"previousmedian",previousmedian); FileClose(handle); }
sir i have changed the code but yet the problem has not been resolved
1)it override the values
2)the values are coming in the same column
sir i have changed the code but yet the problem has not been resolved
1)it override the values
2)the values are coming in the same column
If you want help please answer my simple question . . .
You Open the File, you write to it, then you close it. Then you repeat this . . . read the documentation and then . . . . . explain what you think your code should be doing . . .
handle=FileOpen("cur.csv", FILE_CSV|FILE_WRITE, ';');
sir i have changed the code but yet the problem has not been resolved
1)it override the values
sir i have changed the code but yet the problem has not been resolved
You have only opened to the file for writing (FILE_WRITE). If you check the result of your current call to FileSeek(), I would bet that it is returning false because FileSeek() can't read the file since it has only been opened for writing. You must open the file for both reading (FILE_READ) and writing, so FileSeek() can seek to end-of-file.
handle=FileOpen("cur.csv", FILE_CSV|FILE_READ|FILE_WRITE, ';');
EDIT: Interestingly, FileSeek(handle, 0, SEEK_END) does not return false while the file is opened only for FILE_WRITE, nor does GetLastError() return an error code. If the file is opened only for FILE_WRITE, FileWrite() appears to start at BOF, regardless of FileSeek() to EOF. However, if file is also opened for reading (FILE_READ), FileSeek(handle, 0, SEEK_END) updates pointer to EOF and FileWrite() starts at EOF.
You have only opened to the file for writing (FILE_WRITE). If you check the result of your current call to FileSeek(), I would bet that it is returning false because FileSeek() can't read the file since it has only been opened for writing. You must open the file for both reading (FILE_READ) and writing, so FileSeek() can seek to end-of-file.
EDIT: Interestingly, FileSeek(handle, 0, SEEK_END) does not return false while the file is opened only for FILE_WRITE, nor does GetLastError() return an error code. If the file is opened only for FILE_WRITE, FileWrite() appears to start at BOF, regardless of FileSeek() to EOF. However, if file is also opened for reading (FILE_READ), FileSeek(handle, 0, SEEK_END) updates pointer to EOF and FileWrite() starts at EOF.
Why do you expect FileSeek(handle, 0, SEEK_END) should return false if file is opened with FILE_WRITE only ?
See documentation, a file open with FILE_WRITE only is emptied, so FileSeek(handle, 0, SEEK_END) works normally but the file pointer is already at end and can not be otherwise.
If FILE_WRITE does not combine with FILE_READ, a zero-length file will be opened. If even the file containd some data, they will be deleted.
You can check that behavior by simply opening and closing a file.
int handle; handle=FileOpen("my_data.csv",FILE_CSV|FILE_WRITE,';'); if(handle<1) { Print("File my_data.dat not found, the last error is ", GetLastError()); return(false); } FileClose(handle);
"my_data.csv" file is now empty.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi can some body tell me why my file writing code override the existing values?