10-14-2016 10:39 AM
Hello,
I am using LabVIEW 2013. So write now I am using the "Write to Spreadsheet File" function to write a series of 1D array messages to a text file. The messages are being sent every few seconds or so. I am appending these messages so that the text file stores all the messages sent. However, I am wanting to store only like the last 5 messages, and if a new message comes in, it deletes out the oldest one and stores the new one. Is there a way to do that with the "append" option? And I also want to display the last message sent.
Thanks for any help,
SM
Solved! Go to Solution.
10-14-2016 11:02 AM
I would read in the 5 previous messages, add the latest, remove the oldest, and then overwrite the old data in the file.
10-14-2016 11:02 AM
I can't think of an easy way to do this other than reading the file back into Labview, delete/add data and write it back to file. What is the purpose for doing this? It doesn't make much sense to me but I don't know the whole picture.
10-14-2016 11:05 AM
Putman,
The bigger picture is that the text file will eventually be containing thousands of lines due to the number of messages being sent/written. I don't want to store thousands of lines, only the last few.
10-14-2016 11:06 AM
Wollee,
That is my general idea for doing that, but I am not really sure how to go about doing that. Do you have any examples of this?
Thanks,
SM
10-14-2016 11:07 AM
Another option is to just store the last 4 messages in a shift register. 4 since we only care about writing the last 5 including the new one. Get the new message, append the new message, write to the file (overwriting it), then delete the oldest message from the array and save that in the shift register.
10-14-2016 11:33 AM
Too bad you didn't post your code, which could indicate to us how familiar you are with file I/O. Is there a reason you want to be continually writing to the file? The simplest solution is to simply wait until the end of the program and then do any file I/O that you want (it would be up to you how many messages you save -- you could even save them all and simply write out the last 5, or use a circular buffer of length 5).
Bob Schor
10-14-2016 11:35 AM - edited 10-14-2016 11:35 AM
I agree with Bob and Cross its going to be more effecient to retain those values and update at the end of the application. Is there a reason you want to update the text file while the application is running?
10-14-2016 11:38 AM
I am not very good at LV so that is why I am asking for examples and help lol... The reason why I am wanting to continue writing and while LV is running is because I am receiving these messages from an external source. And if that source was to go down, I need to know what the last few messages were so I can diagnose as to why the source crashed.
Thanks,
SM
10-14-2016 11:59 AM
Here try this example.
Please ask if you have questions.