LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

save data in txt

Hi all, I'm trying to create a program to save data in a txt file, but why is it that after the program is aborted, and we use the same file to save the data, the previous data is overwritten and lost? Is there a way to overcome this? Thanks all.

sinclair15_0-1756915700492.png

 

0 Kudos
Message 1 of 16
(319 Views)

Here's a couple suggestions:

1> When you open the file set it to Open or Create.

2> Set the file position to End before you write to the file.

 

FileWrite.png

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 16
(309 Views)

@RTSLVU wrote:

2> Set the file position to End before you write to the file.


Is it sufficient to set the file position (to "end") right after opening, and before the loop. Inside the loop it will append automatically.

Message 3 of 16
(295 Views)

@altenbach wrote:

@RTSLVU wrote:

2> Set the file position to End before you write to the file.


Is it sufficient to set the file position (to "end") right after opening, and before the loop. Inside the loop it will append automatically.


You are right, setting the position every time before I write is just a habit I fell into. I can't remember exactly why, probably from patching some really bad code I wrote in the past. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 4 of 16
(271 Views)

How do I change the file path while the program is running? I've entered the path in the while loop frame, but it's useless. I have to change the file when the program actually stops. Is there a way? Anyone please help, thanks.

0 Kudos
Message 5 of 16
(228 Views)

@sinclair15 wrote:

How do I change the file path while the program is running? I've entered the path in the while loop frame, but it's useless. I have to change the file when the program actually stops. Is there a way? Anyone please help, thanks.


Yes there is a way..

  1. Close the currently open file
  2. Open a new file  

This can be done programmatically, there's a "Create File with Incrementing Suffix" that can auto generate file names with 001, 002, 003 automatically added to the file name.

 

Now we haven't seen your actual program so I am just going to say that if you are using One Big Loop (OBL) as your program architecture you need to stop and use a proper architecture like a simple state machine. Then doing things like opening and closing new files when necessary or at user request is far easier to program

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 6 of 16
(222 Views)

@sinclair15 wrote:

How do I change the file path while the program is running? I've entered the path in the while loop frame, but it's useless. I have to change the file when the program actually stops. Is there a way? Anyone please help, thanks.


Words are insufficient to describe a program architecture. Once you show us your new code, we can quickly tell what you are doing wrong.

0 Kudos
Message 7 of 16
(196 Views)

sinclair15_0-1757171613306.png

like this? 

0 Kudos
Message 8 of 16
(187 Views)

@sinclair15 wrote:

sinclair15_0-1757171613306.png

like this? 


 

Your code is permanently locked in the inner loop and the path control will only get read once at the start of the program. When you stop the inner loop, both loops will terminate. Think dataflow!

0 Kudos
Message 9 of 16
(181 Views)

ignore about the loops, i just want to be able to control the path and change files while the program is running, how do i do that?

0 Kudos
Message 10 of 16
(167 Views)