LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to File

Solved!
Go to solution

I'm continuosly writing data to 2 columns of a spreadsheet file in a consumer loop. I would like headings (string format) at the top of the spreadsheet. I've attached a snippet of my code showing what I'm doing currently... I want these headings to be written to the file once and write the data to the same file under the relevant headings. However, currently my headings are being wrote to the file on every loop iteration instead of just writing once.

 

I've tried a few different variations of my attached snippet of code including combining the data and heading into one array and using one write to spreadsheet vi but a similiar output occurs

 

I've looked at previous threads highlighting similiar problems but found nothing that helped me with my problem

 

Strokes

 

 

0 Kudos
Message 1 of 5
(2,282 Views)

Post your actual code and I will give you a hand.

Tim
GHSP
0 Kudos
Message 2 of 5
(2,280 Views)
Solution
Accepted by topic author Strokes

Move the header write outside of the loop or put it in a case statement that writes it only on the first iteration using the loop counter.

Message 3 of 5
(2,269 Views)

@aeastet wrote:

Post your actual code and I will give you a hand.


Ernie H's solution is just what I was after, it's working as required now.

 

Didn't think there was much point in posting the code as there's quite a bit of it and the snapshot I provided was the only part of the code that was relevant to my question.

 

However, I will only post code  in future if it's the prefered method of looking for help.

 

Thanks,

Strokes

0 Kudos
Message 4 of 5
(2,257 Views)

Doing this efficiently and easily will require what looks like a lot more code, but in reality will be less.  Start with opening up the write to spreadsheet file and looking at how it works.  You can do a simplified version of this.  Try the following:

 

  1. Before your loop, open the file.  This will produce a file reference.
  2. Create a string containing your column headers separated by a tab character and terminated with an end-of-line constant.
  3. Write this string to the file using the write to text file primitive.
  4. Wire the file reference into the loop using a shift register.
  5. Inside the loop, at each iteration, convert each of your values into a string (lots of options on the string palette)
  6. Concatenate these two values into a single string separated by a tab and terminated with an end-of-line constant.
  7. Write this string to the file.
  8. After the loop, close the file.

Good luck.  If you have any further questions, let us know.

Message 5 of 5
(2,255 Views)