LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you add a column header to a text file?

Hello,

 

I am attempting to add a column header to categorize data logged in a text file in LABVIEW 2016. Below is the block diagram I used and how the data is displayed. I am trying to get the "Data" to stay on top without repeating. 

 

Attempts so far:

- placed the first text file containing the column header in a while loop and the same problem occurred.

- placed the data in a while loop fixed the problem temporarily but the numeric data would not log correctly.

 

If anyone has faced this problem before or knows how to solve it, it would be much appreciated. Thank you. 

 

HGus_0-1588610095931.png

 

 

HGus_1-1588610181883.png

 

0 Kudos
Message 1 of 10
(6,245 Views)

You should attach a VI so we can see all of your code and why it isn't working the way you want.

 

Obviously, writing the row of column headers belongs before the while loop, and the writing of the actual data belongs in the while loop.

 

When you say "placed the data in a while loop fixed the problem temporarily but the numeric data would not log correctly."   Tell us how it was incorrect.

0 Kudos
Message 2 of 10
(6,231 Views)

Well, you are writing an array containing a single elements. What do you expect? What if you would wire the tab delimited string from below instead?

To write the header only once, do it before the loop or place the header code inside a case structure wired to the "exist?) boolean. If the file already exists, don't write the header!

 

altenbach_0-1588612608799.png

 

 

(Learn about "array to spreadsheet string". It would simplify a lot of things in your code ;))

0 Kudos
Message 3 of 10
(6,223 Views)

I attached the VI.

 

Here is the data in the while loop. When I log, note how the data after the date is all the same number. 

 

*The data I am getting is coming from a probe.

 

HGus_0-1588612290374.png

HGus_1-1588612307571.png

 

0 Kudos
Message 4 of 10
(6,221 Views)

Once called, your spinning the loop as fast as the computer allows. Place a small wait inside it. If you are still calling this as a subVI, it will write the same values over and over until stop is pressed. This is not what you want.

 

You should probably keep it as a subVI as before, How often do you call it? (If you call it often, you should keep the file open and use a file ref instead of a path as inputs)

 

Here's functionally identical code (but conditionally writing the full headers) for your subVI. Note that assigned terminals should be on the toplevel diagram, (i.e. outside structures! Details here).

 

altenbach_0-1588614253909.png

 

Message 5 of 10
(6,192 Views)

I expected my data set to come out like this (Figure 1) but I think I am missing something. I replied to another post in this thread, placing the header before the loop and it worked. Now the issue is the data being outputted keeps repeating instead of continuously logging the new data points (Figure 2). 

 


HGus_0-1588614232549.png

                                   Figure 1

 

HGus_2-1588614453673.png

                                Figure 2

 

 

0 Kudos
Message 6 of 10
(6,190 Views)

Thank you, I'm going to try this and see how it works. 

0 Kudos
Message 7 of 10
(6,187 Views)

I tried this VI and it worked, however the headers are not being displayed. Do I need to place it's function in the true structure instead of false?

0 Kudos
Message 8 of 10
(6,175 Views)

It only writes the header if the file doesn't exist already.

0 Kudos
Message 9 of 10
(6,130 Views)

@HGus wrote:

I tried this VI and it worked, however the headers are not being displayed. Do I need to place it's function in the true structure instead of false?


Well, then it does not work. 😉

 

At the moment, it only writes the header if the file was just created (i.e. did not exist before). If you are writing to an existing file, it will not write the header. You can make it smarter where it would read the beginning of the file to check for the presence of the header, but that seems fragile too. Best would be to remove the existing file before testing. If it contains old data, back it up somewhere.

0 Kudos
Message 10 of 10
(6,095 Views)