-
Play videoPlease edit your post.
For large amounts of code, attach it.
string fileHandle = FileOpen("test.txt", FILE_CSV | FILE_READ | FILE_WRITE, "+"); if (fileHandle < 0) {
The third parameter to FileOpen is a Character Constant (a short,) not a string.- The value returned is not a string.
- Why did you ignore the warning "implicit conversion from 'number' to 'string' "
whroeder1:
-
Please edit your post.
For large amounts of code, attach it.
- The third parameter to FileOpen is a Character Constant (a short,) not a string.
- The value returned is not a string.
- Why did you ignore the warning "implicit conversion from 'number' to 'string' "
Thanks whroeder1 for your prompt response. Appreciate your suggestion
for posting code properly. Yes, I have corrected mistake in 3rd
parameter for FileOpen. Sorry, I didn't have fileHandle type as string. It was a typo while placeing code snippet. Actually I do have int type for fileHandle in my .mqh include file.
jpodda: What could happen if I ignore implicit conversion. I thought that MT4 internally do type conversion properly. |
|
whroeder1:
Well explained, Thanks. FYI, I do have fileHandle type as int, but good to know that try not to overlook implicit conversion warnings. Thanks again.
|
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am trying to open .txt file for read and write access to log some information. Following is the code snippet.
int OnInit() {
string fileHandle = FileOpen("test.txt", FILE_CSV | FILE_READ | FILE_WRITE, "+");
if (fileHandle < 0) {
Message("Can't open test.txt in MQL4\\files folder for logging changes. ERROR:"+fileHandle, "Initialization", MB_OK | MB_ICONERROR);
return (INIT_FAILED);
}
if (FileSeek(fileHandle, 0, SEEK_END) == false) {
Message("Error moving pointer to end of file test.txt in files folder for logging changes.", "Initialization", MB_OK | MB_ICONERROR);
return (INIT_FAILED);
}
}
This code returns fileHandle (-1) as return from FileOpen. It is hard to know what causes it as it happens in OnInit on initalization.
Any help will be appreciated.