I am writing status information to a file using the print(file(...)) function. However, I can only append to the file and with a lot of info, the file gets huge. I only need the latest data. Is there a way to overwrite the file data or delete it rather than append to it? (I can't use the File Delete function as it does not work after the file is opened).
TIA
Mike
Writing MultiCharts Status Output to a File [SOLVED]
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Writing MultiCharts Status Output to a File
I'm glad it is possible, but I don't know how to do it.
For test, I tried this:
I thought that perhaps the FileDelete function needed time to complete, so I tried:
This way, on each bar it alternates between writing and deleting. It still only appends. In either case, the delete only occurs once - when the program starts.
What am I doing wrong?
Thanks for your help,
Mike
For test, I tried this:
Code: Select all
vars:
OutputFile("C:\z1\T1.txt");
if LastBarOnChart and barstatus = 2 then begin
FileDelete(OutputFile);
print(file(OutputFile),o,h,l,c);
end;
Code: Select all
if LastBarOnChart and FracPortion(barnumber/2) = 0 and barstatus = 2 then
FileDelete(OutputFile);
if LastBarOnChart and FracPortion(barnumber/2) <> 0 and barstatus = 2 then
print(file(OutputFile),o,h,l,c);
What am I doing wrong?
Thanks for your help,
Mike
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Writing MultiCharts Status Output to a File [SOLVED]
Hello Mike,
Print command does not let the file to be deleted on each calculation.
Instead of print please use FileAppend command.
Print command does not let the file to be deleted on each calculation.
Instead of print please use FileAppend command.
Re: Writing MultiCharts Status Output to a File
That works. Thank you!
eg...
eg...
Code: Select all
vars:
OutputFile("C:\z1\T1.txt"),
OutString("");
if LastBarOnChart and barstatus = 2 then begin
FileDelete(OutputFile);
OutString = NumToStr(o,2) + " " + NumToStr(h,2) + " " + NumToStr(l,2) + " " + NumToStr(c,2);
FileAppend(OutputFile,OutString);
end;