i have problem for close file in MQL4

 

Hello, dear friends,

I have 2 codes for reading and writing a text file in meta4 but I have a problem, my file cant close and still is open and I can't read/write by another application.

Please help me resolve this error ,(before this i just reading text file and i havent problem,after i writing in file i have issue )

string strArr[3];

int handle = FileOpen(per1440,FILE_READ|FILE_TXT,0,CP_UTF8); 


FileSeek(handle,0,SEEK_SET);
int i=0;
while(!FileIsEnding(handle))
{
        if(i>ArraySize(strArr)) { Comment("error: increase size of strArr"); ExpertRemove(); }
        strArr[i] = FileReadString(handle,0);
        i++;
}

FileClose(handle);


// here are variables one after another, order and type are important, triple-check it



var1 = strArr[0];
Cod  = strArr[1];
tech = strArr[2];
int handle = FileOpen(per60,FILE_READ|FILE_WRITE|FILE_TXT,0,CP_UTF8); 

  if(handle!=INVALID_HANDLE)
  {
        FileSeek(handle,0,SEEK_SET);

        FileWrite(handle,var1);
        FileWrite(handle,0);
        FileWrite(handle,tech);
        
  }
  else { Comment("error in varFile write"); ExpertRemove(); }

FileClose(handle);
 
Seyed Alireza Hojjatoleslami:

Hello, dear friends,

I have 2 codes for reading and writing a text file in meta4 but I have a problem, my file cant close and still is open and I can't read/write by another application.

Please help me resolve this error ,(before this i just reading text file and i havent problem,after i writing in file i have issue )

It seems you use ExpertRemove  before closing file. And the handle is left open. Could you close file before ExpertRemove?

 
Yashar Seyyedin #:

It seems you use ExpertRemove  before closing file. And the handle is left open. Could you close file before ExpertRemove?

oh! i didnt see that part , i dont want remove Ex but i  havent  any error so that line never active in meta.
for sure i remove that line . 
thank you my friend

 
Seyed Alireza Hojjatoleslami #:

oh! i didnt see that part , i dont want remove Ex but i  havent  any error so that line never active in meta.
for sure i remove that line . 
thank you my friend

You are welcome!

 
Seyed Alireza Hojjatoleslami:

Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.