LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to write to a existing file but overwrite data just in last row

Solved!
Go to solution
Highlighted

In my DAQ system, columns represent the channels and each row represent the one scan of the data for all channel. it is easy to get file write by append or overwrite to a exist file. But I sometime want just overwrite new data in last row to a exist file. for example: I have DAQ with 10 channels and scan all channel for three times in each run. So my data file will be 10 columns and 3 rows in each run if I set "append" file. next time I want record the data by "overwrite" (so just one row in 3 scans) in the same file but just overwrite in 11th row (so I will keep all the data I previousely got). How can do this?

0 Kudos
Message 1 of 11
(1,828 Views)
Highlighted

Hello,

 

i wrote a longer message but my webbrowser crash and i don't want to rewrite all

 

But tris this vi and tel if this helps

 

Best regards 

 

Tinnitus

 

CLAD / Labview 2011, Win Xp
------------------------------------------------------
Mission d'une semaine- à plusieurs mois laissez moi un MP...
RP et Midi-pyrénées .Km+++ si possibilité de télétravail

Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
Don't forget to valid a good answer / pensez à valider une réponse correcte
0 Kudos
Message 2 of 11
(1,795 Views)
Highlighted
thanks for the reply,  but I cannot open it since my is LV8.0.
0 Kudos
Message 3 of 11
(1,768 Views)
Highlighted

hello,

 

@+

 

Tinnitus

 

 

CLAD / Labview 2011, Win Xp
------------------------------------------------------
Mission d'une semaine- à plusieurs mois laissez moi un MP...
RP et Midi-pyrénées .Km+++ si possibilité de télétravail

Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
Don't forget to valid a good answer / pensez à valider une réponse correcte
Download All
0 Kudos
Message 4 of 11
(1,764 Views)
Highlighted

Hi Tinnitus,

 

when I open the download vi, which asked for "write to spreasheet file (DBL).vi", I ignored because I can not find the vi. the vi I download still can run. I think it instead by "write to spreasheet file.vi". The result I got is still overwrite all but not just last row. I don't know if it is caused by the reason that the "...(DBL).vi" I can not find it.

 

thanks again for the help!

0 Kudos
Message 5 of 11
(1,753 Views)
Highlighted

sorry

 

but i have to go ( 20h00 here)  


I don't understand completly what is the problem, the file asked is just an file to enter for the example , you can type

what you want try1.txt for example , then data will be stored in first time, and seconf time they will be replaced with new values

in this same file ( sorry for  my english , i 'm in a hurry)


 

Regards

 

Tinnitus

 

 

CLAD / Labview 2011, Win Xp
------------------------------------------------------
Mission d'une semaine- à plusieurs mois laissez moi un MP...
RP et Midi-pyrénées .Km+++ si possibilité de télétravail

Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
Don't forget to valid a good answer / pensez à valider une réponse correcte
0 Kudos
Message 6 of 11
(1,747 Views)
Highlighted

anyway, I have understood your ideal in the vi. But that will take longer time since it need to read the whole file if the file already be very large. I tried the similar way as this, it caused the program slower. I want to know if there is the way can directly overwrite just on the last row in the file (at least not to read the whole existing file, for example just set the file position to last row then overwrite in that row).

 

This is question I asked when I took LV trainning class from NI. The tutor can not answer the Q in the calss and said he will give me the answer later, but I still didn't get the answer now.

0 Kudos
Message 7 of 11
(1,736 Views)
Highlighted

Hi GPIB,

 

1) when your lines in the text file all have the same length you can easiy calculate the file offset for the last line.

2) when you know the max length of a line you may simply load the last 1024 bytes (or any appropriate size) of the file and only search in there for the last line. Then you know the seek position to overwrite just the last line...

3) when the line length can be anything from 1 to filesize you have to search from the beginning...

 

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2019 sometimes) on Win10+cRIO
Message 8 of 11
(1,725 Views)
Highlighted

Hi GerdW,

 

I tried your method, but when I seek the file position I still need read whole old file. I thought LV should had this function for overwrite last row, and want to to know if there is this function in new version such as 8.6. (i am using 8.0)

 

thanks for the reply!

0 Kudos
Message 9 of 11
(1,682 Views)
Highlighted
Solution
Accepted by topic author luli8697

Hi GPIB Analyzer.

 

why do you need to read the whole file?

 

You can:

- get the file size with "Get file size" or "file/directory info"

- set the read position with "Set file position"

 

You should subtract 1024 from file size, set this as file position, read 1024 bytes. Now analyze this 1kb of data, find the last row, set file position again, write to file. No need to read the whole file.

 

And as noted before:

How should Labview know the last line in the file without searching for it? You can do this search better than a simple brute force attack Smiley Wink

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2019 sometimes) on Win10+cRIO
Message 10 of 11
(1,663 Views)