07-21-2022 05:34 AM
I developed a code to write information to csv file through labview it working fine but problem lies here is if I written data into csv file for example in 2nd row through labview code after I deleted data in 2nd row by (manually) means that row now is free of data then if I am trying to write data automatically data is being written in 3rd row but I want to write data in 2nd column
07-21-2022 05:59 AM
07-21-2022 09:28 AM
If the LabVIEW code you have written doesn't work, please attach the LabVIEW code (a .VI file) that doesn't work so that we can (a) see what you did, (b) run it ourselves (to make sure LabVIEW itself is working), and (c) help teach you how to fix it and learn LabVIEW at the same time.
One thing that is peculiar about files (and this is true in almost all Programming Languages) -- when you open a file, you start at the beginning, and when you write to a file, you write at the end. So if you have a CSV file consisting of, say, 3 lines, and want to change only the second line, you can open the file, read the first line, but if you try to write the second line (assuming the system lets you do this), you generally set a new "end-of-file" and will lose the third line.
What you need to do, in this case, is something similar to "read the entire file, modify what you need to modify, and rewrite the entire file". Fortunately, LabVIEW's "Read/Write Delimited Spreadsheet" functions allow this.
Bob Schor
07-21-2022 10:19 AM
@Bob_Schor wrote:
One thing that is peculiar about files (and this is true in almost all Programming Languages) -- when you open a file, you start at the beginning, and when you write to a file, you write at the end. So if you have a CSV file consisting of, say, 3 lines, and want to change only the second line, you can open the file, read the first line, but if you try to write the second line (assuming the system lets you do this), you generally set a new "end-of-file" and will lose the third line.
Not true. You just overwrite the bytes already in the file. It is only when you write past the current EOF that the EOF is moved. The danger of overwriting the second line is if you don't write the exact same number of bytes already in the second line, you will either have another line with the data previously in the second line that did not get overwritten or you will overwrite part of the third line. So you really need to read the entire file as an array of strings (each element being a line in the file), replace the data in the second element, and then write the file.
07-21-2022 11:03 AM
I had attached the code
07-21-2022 11:07 AM - edited 07-21-2022 11:08 AM
Hi venk,
@venk_y wrote:
I had attached the code
No, you did not.
All we got is an image showing just some smaller part of your code…
Why do you use so many FormatIntoString and that ConcatString function? Why not use a single FormatIntoString instead???
Where do you even try to replace some existing data in your CSV file? The WriteDelimitedFile function just overwrites the existing file…
07-21-2022 11:10 AM
I will try to change the code by keeping your reply