LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write different .txt files in the same program

Solved!
Go to solution

Hi all!

 

I'm having a problem with my program. I'd like to save a new .txt file each time that I access to a while loop. The thing is that the way that I'm doing, I'm only able to create the first .txt file and when I try to create the second, it gives me an error. 

 

I attach a small example of what I'm trying to do in my big VI to understand it better. 

 

I'd like to save the first .txt file as 1.txt and make a succession like 2.txt, 3.txt, etc.

 

I hope you know how to help me, thank you in advance!

 

Download All
0 Kudos
Message 1 of 9
(3,097 Views)
Solution
Accepted by topic author alarcon7

You could use "create file with incremental suffix".

 

What kind of code is outside the loop? If there is another loop, you could keep track of the suffix in a shift register.

Message 2 of 9
(3,092 Views)

How are you running this code? Are you using the "Run Continuous" button? If so, don't. This is not the way to run a program continuously. You need to use a while loop inside your main VI to continue running until some stop condition is met.

 

You will need to close the current file and then create a new file with the new name. This needs to be done within the main loop which will keep your application running. I recommend that you take a look at state machines. This will help you to design your application.



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 3 of 9
(3,089 Views)

That's a good idea! I've implemented it and now it works. 

 

I also was confusing the while loop where it must go.

 

Thanks!

0 Kudos
Message 4 of 9
(3,061 Views)

Hi Mark!

 

Thanks for your answer, I wasn't using run continuous mode. Anyway, "This needs to be done within the main loop which will keep your application running. I recommend that you take a look at state machines. This will help you to design your application" it has been useful for me.

 

 

 
0 Kudos
Message 5 of 9
(3,058 Views)

@altenbach wrote:

You could use "create file with incremental suffix".

 

What kind of code is outside the loop? If there is another loop, you could keep track of the suffix in a shift register.


I've heard that VI slows down as you add more files because it has to keep track of them all?  Instead, I like to add a timestamp to the name to make it unique.  YYYY-MM-DD and time in 24-hour format (either replace the : or delete them, as they aren't allowed in the Windows file name.)  Usually to the second is good enough, but you can go into fractional seconds if the files are written very quickly.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 9
(3,057 Views)

I suppose you could also add the increment [i] to the file name if you don't mind "0.txt" and you don't mind it being limited to "2147483647.txt".

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 9
(3,051 Views)

@billko wrote:

@altenbach wrote:

You could use "create file with incremental suffix".

 


I've heard that VI slows down as you add more files because it has to keep track of them all?  


You heard right, but it is typically not a problem unless the number of files gets very huge. For example if you already have existing files from previous runs in that folder, this tool ensure that you continue where you left off. (e.g. if you already have file000.txt through file007.txt, it will create file008.txt and it will not try to overwrite existing files). This might be important.

 


@billko wrote:
YYYY-MM-DD and time in 24-hour format (either replace the : or delete them, as they aren't allowed in the Windows file name.)  Usually to the second is good enough, but you can go into fractional seconds if the files are written very quickly.

I just use the date/time in seconds formatted to a fixed width, zero-padded Hexadecimal. Unique AND timezone invariant. 😄

0 Kudos
Message 8 of 9
(3,030 Views)

@altenbach wrote:

@billko wrote:

@altenbach wrote:

You could use "create file with incremental suffix".

 


I've heard that VI slows down as you add more files because it has to keep track of them all?  


You heard right, but it is typically not a problem unless the number of files gets very huge. For example if you already have existing files from previous runs in that folder, this tool ensure that you continue where you left off. (e.g. if you already have file000.txt through file007.txt, it will create file008.txt and it will not try to overwrite existing files). This might be important.

 


@billko wrote:
YYYY-MM-DD and time in 24-hour format (either replace the : or delete them, as they aren't allowed in the Windows file name.)  Usually to the second is good enough, but you can go into fractional seconds if the files are written very quickly.

I just use the date/time in seconds formatted to a fixed width, zero-padded Hexadecimal. Unique AND timezone invariant. 😄


You're always a few steps ahead of me.  😄

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 9
(3,023 Views)