LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I first clear data then save to a file

Solved!
Go to solution

Hello Folks,

 

I need help from you.

 

This is what I’m trying to do:

 

Whenever I save the .txt file, first, it will clear my current file data and then save new data.

It can be a simple solution, but unfortunately, I could not be able to get it.

 

Appreciate your effort.

- Reduanul

0 Kudos
Message 1 of 16
(3,833 Views)

Hi REDUANUL,

 


@REDUANUL wrote:

Whenever I save the .txt file, first, it will clear my current file data and then save new data.

It can be a simple solution, but unfortunately, I could not be able to get it.


When you want to append data to a file then you need to append that data - instead of overwriting the file or recreate it!

 

Btw. when there is a problem in YOUR code then you should attach YOUR code. (We cannot debug text/images using LabVIEW…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 16
(3,830 Views)

@REDUANUL wrote:

This is what I’m trying to do:

Whenever I save the .txt file, first, it will clear my current file data and then save new data.


So your goal is to replace or create your file.  There is an input on the Open/Create/Replace File node called "operation" where you could set that.


GCentral
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 3 of 16
(3,818 Views)

Hello GerdW,

 

Here are my subVI snipped.

 

SubVI.png

 

First, I have created a file. After one execution file is being replaced, each time string values are saved but with existing data. Probably here, I need to make some changes (if I didn't get you wrong). But not getting what will be the changes!

0 Kudos
Message 4 of 16
(3,782 Views)

Hello crossrulz,

 

Yes, I did it.

 

Here what I did:

 

SubVI.png

 

Everything works for the initial saving operation, but when the second time (and later on) I am saving, data is adding with exiting string values. 

0 Kudos
Message 5 of 16
(3,777 Views)

You are placing the file pointer to the end of the file therefore you are simply appending the data. Don't set the file position and see if you get your desired results.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 16
(3,773 Views)

Hello Mark Yedinak,

 

I tried it but not working. Same thing happening (appending with existing file) 😞

 

 

0 Kudos
Message 7 of 16
(3,758 Views)

If you are replacing or creating a file, there is no reason to set the file pointer to the end.


GCentral
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 8 of 16
(3,748 Views)

Hi Reduanul,

 


@REDUANUL wrote:

First, I have created a file. After one execution file is being replaced, each time string values are saved but with existing data. Probably here, I need to make some changes (if I didn't get you wrong). But not getting what will be the changes!


What is your goal?

Do you want to append new data to an already existing file?

Or do you want to create a new "fresh" file with each run of that VI, "deleting" the old content and only write the new data to the file?

 

Your explanations aren't clear until now (IMHO)…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 16
(3,736 Views)

Hello GerdW,

 

Here is my explanation:

 

I have created a file as of now. But want to append new data to an already existing file by "deleting" the old content and only write the new data to the existing file.

 

I hope now it's clear.

 

 

0 Kudos
Message 10 of 16
(3,712 Views)