Markus
FileOpen(file_name,FILE_BIN|FILE_READ|FILE_WRITE)
does not work the same way it worked earlier. I am creating a text file to store some text. Has there been a change/bug fix for File Open method in these builds?
What are the proper arguments to use with File Open for text file creation?
FileOpen(file_name,FILE_BIN|FILE_READ|FILE_WRITE)
does not work the same way it worked earlier. I am creating a text file to store some text. Has there been a change/bug fix for File Open method in these builds?
What are the proper arguments to use with File Open for text file creation?
Definitely not FILE_BIN. And you may want to omit FILE_READ to create a new file to replace the existing one.
handle = FileOpen(file_name, FILE_READ | FILE_WRITE); FileSeek(handle, 0, SEEK_END);
- to append text to the existing file or just
handle = FileOpen(file_name, FILE_WRITE);
to create a new file.
Both seem to be working okay.
However, I had to revert back to build 178. With this build, FileOpen(file_name, FILE_READ|FILE_WRITE) successfully creates file on the first run and opens it for appending records in subsequent runs. (see code below)
Again, moved build to 184, recompiled the same code: file fail to be created. Tried various flag combinations: same result. GetLastError() does not return a meaningful error. It looks like a bad build/ compilation bug to me.
Ok, code:
string file_indicator="status.txt"; void file_clear(string file_name){ int file_handle; file_handle=FileOpen(file_name,FILE_READ); FileClose(file_handle); if(file_handle>0){ FileDelete(file_name); } } void file_record(int record,string file_name,string value1){ if(record==0){ return; } int file_handle; file_handle=FileOpen(file_name,FILE_READ|FILE_WRITE); int error_code=GetLastError(); Print("file:",file_handle," err:",error_code," dsc:",ErrorDescription(error_code)); FileSeek(file_handle,0,SEEK_END); FileWrite(file_handle,value1); FileFlush(file_handle); FileClose(file_handle); } void init(){ file_clear(file_indicator); } void start() { file_record(1,file_indicator,"some text to record"); }
Now, when I look at it: it also might be the fact that this method is within another function call. But it should not. Ok, any ideas?
I have tried the above code on my 184 and it works perfect
The only thing I had to change was function definitions:
void start() to int start()
void init() to int init()
I had just realized what it might be. I am using build from Neuimex, not MetaQuotes. They must be messing up their build upgrades.
Thank you guys for your help and ideas.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The new build includes the following changes:
1. Fixed "Common error" of terminal connection;
2. Fonts of charts have fixed size, they don't depend on font settings of the operational system anymore;
3. Added GetObjectVisibility(), SetObjectVisibility(), SetLevelValue(), SetLevelStyle(), FirstVisibleBar(), BarsPerWindow() functions; parameters MODE_MINLOT, MODE_LOTSTEP in the function of MarketInfo() function;
4. Fixed appearance of comments for pending orders;
5. Added functionality to assign hot keys for indicators, expert advisors and scripts through context menu of the "Navigator" window;
6. Settings of the terminal toolbars were transferred to the file of terminal.ini;
7. Improved work of the Client Terminal in two monitors;
8. Added Turkish and Spanish interface languages;
9. Modified coloring of modeling quality indicator considering initial and end dates of testing;
10. Fixed "Trade context is busy" error during expert advisor trading;
11. Improved work of the terminal through Data Centers;
12. Fixed calculation of margin requirements when testing experts on futures;
13. Improved calculation of cross currencies when testing;
14. Strategy Tester symbol list is updated when relogging;
15. Updated MetaEditor Dictionary.
MetaTrader 4 download link: "MetaTrader 4 trading terminal"