Download MetaTrader 5
To add comments, please log in or register
What is a social trading? Read the article to find that out!
Peter Williams
342
Peter Williams 2016.03.30 16:13 

The code appears to executes OK ( i.e. reads details from file and My_Handle_line seems OK - 2) -but still generates the ERROR code 5008

My_Handle_Line  = FileOpen("Dashboard\\"+fname, FILE_CSV|FILE_READ, "|");          
                        Write_my_Error("80010A My_Handle_Line = "+DoubleToString(My_Handle_Line,0));  FileFlush(My_Handle);
//..........................................................................................................................
   if( My_Handle_Line > -1 ) 
   {  str1 = FileReadString(My_Handle_Line);          Write_my_Error("80010D Test");  FileFlush(My_Handle);

The following is from my own log file ~ but don't know how to resolve

>>>>>>>>>>>.... 80010A My_Handle_Line = 2 My_error: 5008 wrong file handle (handle index is out of handle table)

I don't get an error resulting from code below and str1 is read correctly

FileReadString(My_Handle_Line)

whroeder1
13620
whroeder1 2016.03.30 17:54  
You open a file. Do you ever close the handle?
Peter Williams
342
Peter Williams 2016.03.31 08:01  
WHRoeder:
You open a file. Do you ever close the handle?

Yes I close files etc ...... found the problem ..... I used FILEFLUSH 0n the read file.


Didn't find the actual error message very helpful - perhaps just a pointer in the right direction


Thanks again - as always - for your speedy response

Ovo Cz
2951
Ovo Cz 2016.03.31 09:18  
Demos:

hello there :)

I would like to ask about that line, if you do not mind. I can see that you are testing for the File Handle to be 0 or more; and here is my question: a file handle in MQL is a integer, as we all know. That integer presummably stores the address of the location of the file buffer (a pointer in C) - it may not be a label or something. So two things

a) Let us assume that this number  is the address in the hdd/ssd. Then i doubt it can be 0, as there is the OS anyway

b) If it is a "pointer" in a memory place, that serves as the start of the file buffer, then this place can not be 0: Windows will not let you write in the physical address 0 (NULL pointer is not accessible in Windows - see https://en.wikipedia.org/wiki/Zero_page )

To conclude, i believe you can write if( My_Handle_Line > 0 ) 

best regards 

The MQL file handle is valid only for the current script and handles are numbered 1, 2, 3 etc., not related to anything you assume.
Demos Stogios
184
Demos Stogios 2016.03.31 11:43  
Ovo:
The MQL file handle is valid only for the current script and handles are numbered 1, 2, 3 etc., not related to anything you assume.

ok, after looking at the manual i realised that MQL likely indexes the handles that obtains (from Windows) as file handles and offers those indices as handles; or something in that line hehe -  ihave to have a look at Win32 API

A final remark, if numbering starts from 1 and not 0 then it should be My_Handle_Line > 0 and not -1 right ?

best regards 

whroeder1
13620
whroeder1 2016.03.31 12:22  
Demos: if numbering starts from 1 and not 0 then it should be My_Handle_Line > 0 and not -1 right ?
Wrong. RTFM
  1. FileOpen - File Functions - MQL4 Reference states that on a error it returns INVALID_HANDLE (-1)
  2. No where does it states that valid handles starts at 1. (Same as ticket numbers)
Demos Stogios
184
Demos Stogios 2016.03.31 13:26  
WHRoeder:
Wrong. RTFM
  1. FileOpen - File Functions - MQL4 Reference states that on a error it returns INVALID_HANDLE (-1)
  2. No where does it states that valid handles starts at 1. (Same as ticket numbers)

Allright, i was looking somewhere else in the reference and did not see that one. Meanwhile, i was looking around the internet and found that one 

https://blogs.msdn.microsoft.com/oldnewthing/20040302-00/?p=40443 

it says a thing or two about why CreateFile returns -1 in Windows API and not 0. Back OT, i printed the handle of the first file opened in a EA and guess what, it was number 1 :) So maybe fail code can be -1 or 0, depending on the function but handles likely start at 1 in MQL

Ovo Cz
2951
Ovo Cz 2016.03.31 15:42  
Demos:

Allright, i was looking somewhere else in the reference and did not see that one. Meanwhile, i was looking around the internet and found that one 

https://blogs.msdn.microsoft.com/oldnewthing/20040302-00/?p=40443 

it says a thing or two about why CreateFile returns -1 in Windows API and not 0. Back OT, i printed the handle of the first file opened in a EA and guess what, it was number 1 :) So maybe fail code can be -1 or 0, depending on the function but handles likely start at 1 in MQL 

Give up such effort, MQL has a constant INVALID_HANDLE, while windows have INVALID_HANDLE_VALUE, both substitute for -1.

Why would any coder look for another undocumented value like you? 
Peter Williams
342
Peter Williams 2016.03.31 16:04  
Ovo:

Give up such effort, MQL has a constant INVALID_HANDLE, while windows have INVALID_HANDLE_VALUE, both substitute for -1.

Why would any coder look for another undocumented value like you? 

Hi Guys


Didn't intend to start an argument but thanks both your comments

WHRoeder - thanks again

/
To add comments, please log in or register