- How to create a two-dimensional array and fill it with the product of the respective row index and column index
- How do you algorithmise the detection of MA feed clusters?
- [WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you.
Each time I read from a file and close the file, the filebecomes empty the next time I want to read or write to the file. Whatmechanism or function can I use to retain the content of the file inorder to add to the existing content of the file or read the file againon the next opening of the file. I want the file to retain its contenteven when I restart the computer. Thank you in advance.
Check documentation on flags for FileOpen() command, especially this part:
There are some specific features of work when you specify read and write flags:
•If FILE_READ is specified, an attempt is made to open an existing file. If a file does not exist, file opening fails, a new file is not created.
•FILE_READ|FILE_WRITE — a new file is created if the file with the specified name does not exist.
•FILE_WRITE — the file is created again with a zero size.
Check documentation on flags for FileOpen() command, especially this part:
There are some specific features of work when you specify read and write flags:
•If FILE_READ is specified, an attempt is made to open an existing file. If a file does not exist, file opening fails, a new file is not created.
•FILE_READ|FILE_WRITE — a new file is created if the file with the specified name does not exist.
•FILE_WRITE — the file is created again with a zero size.
My question is how to add a new record to an existing file which already has some records. I am not reading, I am WRITING (adding records). All you have talked is about a file not existing or file existing or deleting a file and creating a new one. Just assume that the file exists and that the system can see the file. How to add a new record to the file after opening. That is the task. Please read my question carefully before answering @drazen64. Thank you in advance.
Each time I read from a file and close the file, the filebecomes empty the next time I want to read or write to the file. Whatmechanism or function can I use to retain the content of the file inorder to add to the existing content of the file or read the file againon the next opening of the file. I want the file to retain its contenteven when I restart the computer. Thank you in advance.
My question is how to add a new record to an existing file which already has some records. I am not reading, I am WRITING (adding records). All you have talked is about a file not existing or file existing or deleting a file and creating a new one. Just assume that the file exists and that the system can see the file. How to add a new record to the file after opening. That is the task. Please read my question carefully before answering @drazen64. Thank you in advance.
macpee: I am not reading, I am WRITING (adding records).
| There are no mind readers here. We can't possibly know what you are doing. Don't just tell us what you think you are doing, post your code. |
My question is how to add a new record to an existing file which already has some records. I am not reading, I am WRITING (adding records). All you have talked is about a file not existing or file existing or deleting a file and creating a new one. Just assume that the file exists and that the system can see the file. How to add a new record to the file after opening. That is the task. Please read my question carefully before answering @drazen64. Thank you in advance.
actually, the answer you got there was the right one. The manual is not really clear about it, but you have to include FILE_READ in order for your file not to get zeroed each time you open it
Ok I am sorry if I have sounded ambiguous @drazen64. The code is as follows:
int FetchHandle=FileOpen("FetchFile.txt",FILE_WRITE|FILE_CSV|FILE_TXT); for (j=1; j<=5; j++) { FileWrite(FetchHandle, j, FetchContent) FileClose(FetchHandle); }
The idea is to add a new record each time the program loops. The file closes within the loop, but should retain the initial records at next open. Thank you in advance
I am not reading, I am WRITING (adding records). No you are not. This create a empty file. This is what drazen64 already told you. | int FetchHandle=FileOpen("FetchFile.txt",FILE_WRITE|FILE_CSV|FILE_TXT); |
You need to append to a file (note the FILE_READ|FILE_WRITE and the seek to end) | int CREATE = FILE_WRITE|FILE_TXT|FILE_ANSI; int APPEND = FILE_READ|CREATE; string fileName = WindowExpertName() + ".DBG"; HANDLE handle = FileOpen(fileName, APPEND); if(handle != INVALID_HANDLE){ FileSeek(handle, 0, SEEK_END); FileWrite(handle, s); FileClose(handle); |
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use