06-21-2017 05:48 AM
Hello there,
I am trying to save data into a text or spreadsheet file, with headers for each column.
My data needs to be entered as an entire row or column, and any subsequent row/column needs to be appended as per user request. I have made a graphical descriptor:
I want to create a file, write the headers, write data set 1, save/close the file, reopen when requested, add data set 2, save/close file, etc.
I've tried read/write text file, read/write spreadsheet file, but none seem to work without adding data row by row. Any help is welcome.
Ben
06-21-2017 06:58 AM
You don't need to Read and then use Replace Array Subset.
To start with, Build Array more clearly carries out the operation you want here (append to array), but there's no need to do that either because you can wire the new results to the 1D array input of the Write (outside of the case structure) and just set the optional boolean to True for Append Data (by default it is false).
06-21-2017 08:04 AM
Here are two things you might try, depending on what Toolkits you have available for your LabVIEW 2013 installation.
Now that I've stated it this way, Option 2 (which doesn't need the Toolkit) seems like a piece of cake. Note that you'll get Text files (not .xlsx files) with this latter method.
Bob Schor
06-21-2017 08:26 AM
Thank you for the suggestion cbutcher but it doesn't work. It will append the new array to column 1. I can't get it to append under column 2, 3, 4... etc
My issue is I can't specifically request it to append to my chosen column.
06-21-2017 08:34 AM
Hi Bob,
Thank you for your reply.
Are you suggesting I write the header for each column sequentially while simultaneously writing the data underneath it by appending? Therefore each iteration adds the next column header and its respective data?
So in this case I think I would have to read the relevant value of the 1D header array, incrementing through the array by 1 each time it is called/accessed. I would need to extract the row size of the main file, use that as the index for the string array, and then add the data underneath it.
Text files are no problem, anything Excel can read is good for me.
Ben
06-21-2017 11:01 AM
I found that if I just appended the 1D array data to the header, in subsequent writes it replaced the string header data with 0. So I started as a string spreadsheet and converted everything to strings. It now works as intended.
I have attached the complete vi for anyone who is interested.
Please note, this is NOT the way I wanted the code to work. In some ways I think it is a poor hack.
I wanted to generate all the string headers at the beginning, a full row of headers, and add each 1D array to each column in turn, underneath its respective header. But unfortunately there is no good way to do that in labview.
There seems to be no concise function that allows: "Insert this 1D array into this 2D array starting at this position in the 2D array"
Ben
06-21-2017 11:16 AM
If you don't mind using a csv file, then you can use Write Text File to do what you want. It still requires string inputs, but that's effectively all you get with a text file...
There's a function in the string palette that allows you to set the file position - you can set relative to the end of the file to move the position to the end (I.e. append). You need to do this every time you open the file reference if you go this route.
06-21-2017 01:51 PM
Your text file name is "test6(3).txt" so I am assuming that it is NOT an excel file. Rather a comma or tab delimited text file.
I cleaned up your VI:
You don't need the stacked sequence with the event structure. Just make the boolean's mechanical action to be "Latched when Released" and put each control in its respective event.
You don't need the timeout event. You don't do anything there.
Add a "STOP" event.
I replaced the deprecated Write to Spreadsheet File.
You don't need to read the old data->append the new data to that->then rewrite all the data to the file. Just set the boolean to append the data to the file.
06-21-2017 02:35 PM
Hi jamiva,
Thank you for your reply!
I am out of office/lab for a few days but I will clean it up when I get back. I can't tell exactly from your image, but the last time I used a simple append to add the next data set to the file it just appended it on the end of the first column. I couldn't get it to add the second set of generated voltages underneath the second header (e.g. T1 UP).
Unless I'm misunderstanding what the new "write to" symbol does (I'm not familiar with it by eye), it looks like that will give you one long column of data?
Ben
06-29-2017 05:02 AM
Hi jamiva,
Could you possibly attach the .vi you made in your example?
Thank you