LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Empty file after replace

Solved!
Go to solution
Highlighted

Hello

 

I am facing a very strange problem saving files. Find attached a quick example showing the issue.

 

The first time I hit "save" and choose a name for the file (numbers.txt, for example), everything works great and the file is created with my data. Nevertheless, if I save the file numbers.txt the first time and then I click on "save" again and choose the same name for the file and click YES after "The file already exists. Do you want to replace it?", the file numbers.txt is replaced, but it gets empty!!!! If I click on "save" again and choose another name (results.txt, for example), the file results.txt is created properly. If I try to replace the file results.txt I will get the same error with an empty file again.

 

I think that the issue has something to do with "trying to write SAME DATA TWICE in a file", even choosing to "replace" the file. If you stop running the VI, start again, and try to save replacing a file that already exists, the file will not get empty.

 

????

 

Thanks.

 

Dan07

 

0 Kudos
Message 1 of 4
(858 Views)
Highlighted

Hi Dan,

 

I can save the same file several times - and it always has the same content after saving/replacing... (using your VI in LV2009)

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
0 Kudos
Message 2 of 4
(845 Views)
Highlighted
Solution
Accepted by topic author dan07

Dear Dan07,

 

After you are done writing to the file, you should finish the whole operation with closing the file. Also, your original code writes the same set of random nubers to the file all the time. If you place the random nuber generation code inside your while loop, it will run every time you press the save button and it will generate a new set of random numbers. Please see the attached snippet for an example.

If you have any further questions, please feel free to ask!

 

Daniel

Dániel Fülöp
Field Application Engineer (CLA, CTA)
National Instruments
0 Kudos
Message 3 of 4
(836 Views)
Highlighted

Dear Daniel,

 

You are right about "closing the file" after operation. How could I miss that??? Thanks!

 

This VI was just an example and saving the same set of data over and over again is not a problem.

 

Take care.

 

Dan07.

0 Kudos
Message 4 of 4
(821 Views)