LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DATA OPERATION IN CSV FILE

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

0 Kudos
Message 1 of 7
(1,858 Views)

Hi venk,

 

it seems there is something wrong in your code.

But you decided not to attach your code, so you have to debug on your own!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(1,854 Views)

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

0 Kudos
Message 3 of 7
(1,832 Views)

@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.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 7
(1,822 Views)

I had attached  the code 

0 Kudos
Message 5 of 7
(1,812 Views)

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…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 7
(1,809 Views)

I will try to change the code by keeping your reply

0 Kudos
Message 7 of 7
(1,803 Views)