05-31-2012 09:05 AM
Hello all, I am pretty new to labview, and I've seen variations of this question asked, but none have really quite answered it the way I need it to. So my question is this: I want to put data underneath column headers, then append only the data. Right now I have it set up so it appends both the header and the data every run. I will attach the code I am using, the output file that my code produces, and the sample file which is what I would like my output file to look like. The files attached are .xls but I will be using .csv. (Attachment issue) Thanks in advance.
05-31-2012 09:19 AM
05-31-2012 10:00 AM
Thank you, now how would you go about doing this on a "Write to Text File" block?
05-31-2012 10:08 AM
Hi Szklanam,
I'd consider doing this using the 'Write to Spreadsheet' VIs. This link shows how you can add a header to the spreadsheet file.
Hope it helps,
-CC
05-31-2012 10:09 AM
05-31-2012 10:13 AM
Good advice Gerd. The context is always your friend when using new functions. You can also click on the 'detailed help' text to get a much more detailed breakdown of the VI.
-CC
05-31-2012 01:05 PM
Which context help? The "Write to Spreadsheet" or "Write to Text File"? They both sort of lack description when it comes to appending new data. The append section of the "Write to Text File" help is awful. It mentions something about the EOL but doesn't really describe how to append data. And for the link, that way is not working. I assumed that on the first "Write to Spreadsheet" block I would be attaching the header, and then set the append to file terminal to false or leave it blank. Then the second "Write to Spreadsheet" block would be my data and then that would have the append to file terminal set to true. That setting will not let me run it through a loop. I get the last data value with no headers. Or if I switch up the settings I just get what I've been getting
05-31-2012 01:16 PM - edited 05-31-2012 01:19 PM
Hi Szklanam,
the context help for "Write to Text file" says "If you wire a file refnum to the file input, writing begins at the current file position. To append to an existing file, set the file position to the end of the file by using the Set File Position function." as can be read here...
You wrote:
"Then the second "Write to Spreadsheet" block would be my data and then that would have the append to file terminal set to true. That setting will not let me run it through a loop."
Why can't you use a loop here? Which "setting" are you talking about?
"I get the last data value with no headers."
Isn't that what you want? To write the latest data values without a header?
Why don't you attach a VI to show what you have programmed so far?
05-31-2012 01:54 PM
I would write the headers as part of my create file routine. Then you just add the data to your file until you are done and close it.
05-31-2012 02:08 PM
I can only attach snippets due to company policy. I have an array constant of string type with my headers, and an array of string type which includes my data. My header constant is going into the first "Write to Spreadsheet" 2D array terminal, the delimiter is a comma, append to file is false, and there is a file path going into the file input terminal. The file out is going to the file in of the second "Write to Spreadsheet". My data string is converted to a numeric array with "Format Value" block with the format of %0.6f and the delimiter is a comma. This goes to a for loop with auto indexing, and then from there goes to the 1D array input of the second "Write to Spreadsheet" block. The delimiter for this "Write to Spreadsheet" block is also a comma, and the append to file for the second "Write to Spreadsheet" block with the data coming into it is set to true. So my thinking about this is that the first "Write to Spreadsheet" block reads in the headers, the append is false so it will not append anything else, and the second "Write to Spreadsheet is in a loop that knows when the array is done, and that is appending so each new value would append depending on the number of tests I do. But what happens is I either get no headers and one set of numbers (The last run to be completed), headers and data (only the last run to be completed) or headers and data for each run instead of just getting one set of headers then data for the rest of the runs.