FileWrite Problem

 

Hello

I have a problem writing to a file.

These are the two first cells in the CSV file:

none

none

After running this line:

FileWrite(handle,"AUDCHF");

The result is :

AUDCHF

ne

The problem is, why the FileWrite function removes the first two characters from the second cell?

Thanks

 
jackbwa:

The problem is, why the FileWrite function removes the first two characters from the second cell?

Your code, which we cannot see, is broken.

nonenone
AUDCHFne

you are overwriting your existing data . . .

 

Thank you RaptorUK for your fast respond.

I’m testing with this code:

handle=FileOpen("AlertPairsFile.csv", FILE_CSV|FILE_READ|FILE_WRITE, ';');
  if(handle>0)
    {
              FileWrite(handle,"AUDCHF");                      
     FileFlush(handle);
     FileClose(handle);
    }              

If I put the text "AUDC" in the FileWrite above then it works great and will not remove from the next line. So do I need to put only 4 characters in the FileWrite in order for the code to work fine?

 
jackbwa:

Thank you RaptorUK for your fast respond.

I’m testing with this code:

If I put the text "AUDC" in the FileWrite above then it works great and will not remove from the next line. So do I need to put only 4 characters in the FileWrite in order for the code to work fine?

If you want to add to the end of the file you first need to seek to the end of the file . . .

FileSeek(handle, 0, SEEK_END);

. . . I've not done it but I assume if you want to add to the start of the file you will need to make room by moving the other contents along in the file.

 

I did try the Seek End before, it works great.

But here I have another situation.

I have another function that open the CSV file, then search for a cell with some value and replace it with the current symbol of the chart, so I don’t want the FileWrite to remove anything from the next cell.

I guess I will use only the first 4 characters from the symbol. I also tried to write to the file “audchf” instead of “AUDCHF” but the same results.

 
jackbwa:

I did try the Seek End before, it works great.

But here I have another situation.

I have another function that open the CSV file, then search for a cell with some value and replace it with the current symbol of the chart, so I don’t want the FileWrite to remove anything from the next cell.

I guess I will use only the first 4 characters from the symbol. I also tried to write to the file “audchf” instead of “AUDCHF” but the same results.

If you try to replace none 4 characters with AUDCHF 6 characters you will have issues, instead of none use -none- or do it properly and read everything after the place where you want to insert AUDCHF into an array, write the AUDCHF to it's place in the file then write the contents of the array after the AUDCHF . . .
 

Thank you RaptorUK

you gave me breakthrough.

Thanks

Reason: