From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Open Create Replace problems with saving file patterns

Solved!
Go to solution

Hello, I got a problem with open/replace/create function. Could you please clarify each function how it works? As you can see in my file, I try to save into the specified file path. The values appear in the text file but when I change some values in the data mainstream, it replaces the old value it has been. I want to have the whole data in one file till I close it and open another file for the operation.

 

How can I do it??

 

Thank you

0 Kudos
Message 1 of 11
(3,168 Views)

You are opening and closing the file on every loop iteration.  Are you sure that is what you want to do?

 

The reason the data is getting replaced is that when you open the file, the file pointer is at the beginning, so the data gets put there.  If you want to put new data at the end, then you need to set the file position to the end of the file before you write the new data.

0 Kudos
Message 2 of 11
(3,160 Views)

So I should take "close file" out from the big loop?

0 Kudos
Message 3 of 11
(3,148 Views)

What did you mean by "set the file position at the end of the file"?? Which block should to move to where?

0 Kudos
Message 4 of 11
(3,143 Views)

Search the palettes for "Set File Position".

 

Take both the open and the close file VI's out of the loop.

0 Kudos
Message 5 of 11
(3,134 Views)
Solution
Accepted by topic author Bombbooo

i think its in programming->file io-> advanced file functions

Please remember to accept any solutions and give kudos, Thanks


LV 8.6.1, LV2010,LV2011SP1, FPGA, Win7
0 Kudos
Message 6 of 11
(3,132 Views)

Hi,

 

I can't see your VI as it is in a newer version of LabVIEW than I have, so if you want any more specific help you'll need to save the VI as a previous version. (File -> Save as previous version) I have LabView 2009.

 

However, I have made a quick little example you could use. You don't need to use Set File Position if you use Shift Registers, as shown in the attached picture.

 

David.

0 Kudos
Message 7 of 11
(3,128 Views)

That is a good simple example of how to open the file, write to it in a loop, and close it afterwards.

 

But shift registers have nothing to do with why you don't need to set the file position.  You don't need to set the file position because when the file remains open, the file functions know that the file position is after the data it last wrote out.  Closing and reopening a file causes the file position to be reset to the beginning of the file.

Message 8 of 11
(3,123 Views)

Oh you're right. Sorry, didn't think my answer through 🙂

0 Kudos
Message 9 of 11
(3,117 Views)

here we go the 2009 version. I tried to take all out from the loop. it seems working without using the set file position.

0 Kudos
Message 10 of 11
(3,102 Views)