Update CSV File

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
8
domalu 2016.04.04 23:01 #
 
WHRoeder:
domalu: Considering you are referencing records, in my case the size of each record will always be fixed length.
1, A, Y
2,B, Y
3,C,Y
  1. Your first field is an int. Will that always be [0..9]? Otherwise it is not fixed length.
  2. Your record is three fields, not fixed length

Yes, it will always be the same within that range.

Maybe I wasn't clear earlier, there will be 3 columns and of same size(always) for this scenario.


avatar
2017
gooly 2016.04.04 23:31 #
 
domalu:

>>or (I would) read the entire file into your 2-dim. array change some of the data and re-write the entire csv-file.

Can you please give me a sample code for this.

Thanks.

I am using Windows' kernel functions.

But you can look here and here.

As I said, I read the entire file (file-length) and first split by \n into the line-array and then I split each line into items.

avatar
8
domalu 2016.04.08 03:12 #
 
gooly:

I am using Windows' kernel functions.

But you can look here and here.

As I said, I read the entire file (file-length) and first split by \n into the line-array and then I split each line into items.

Gooly,

Thanks for the link. And here is where I am struggling with getting the concepts in order.

Will I be able to write to overwrite the same file or it will be a new file ? My requirement is, it needs to be the same file and second thing if I read the contents thru a loop perhaps

      for(i=0;i<StringLen(str);i++)

how can I overwrite the file as I am reading the file? Will be appreciated if you can provide me a sample script related to my example

Thanks.


avatar
2017
gooly 2016.04.08 10:15 #
 

1) Open the file only to read it, follow the advises of my second link. CLOSE it, do something and then write it. Opening a file solely to write empties an existing file completely.

2) Don't read char by char but item by item use the advises of my second link: e.g. handle=FileOpen("test.csv",FILE_READ|FILE_CSV,',');

3) May be if you create the string to write you csv-file don't your "\r" and/or "\n".

Just experiment a bit and learn how one handles files.

You even can google "mt4 read csv integer".

I can promise you all you need has already been published.



avatar
8
domalu 2016.04.08 15:48 #
 
gooly:

1) Open the file only to read it, follow the advises of my second link. CLOSE it, do something and then write it. Opening a file solely to write empties an existing file completely.

2) Don't read char by char but item by item use the advises of my second link: e.g. handle=FileOpen("test.csv",FILE_READ|FILE_CSV,',');

3) May be if you create the string to write you csv-file don't your "\r" and/or "\n".

Just experiment a bit and learn how one handles files.

You even can google "mt4 read csv integer".

I can promise you all you need has already been published.



Gooly - Thank you. Will try and let you know how that goes.
Back to topics list   | 1 2  

To add comments, please log in or register