LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to spreadsheet in a while loop??

I have a VI that reads several pressure data from analog inputs and shows them in a chart. Now I also want to save these data to a file. If I place the write-vi inside the while-loop I get only one data, before it asks for filename again. If I place it outside the loop, nothing happens.. See my VI in the enclosed file.
Any suggestions??
0 Kudos
Message 1 of 6
(6,996 Views)
you can use a shift register - you will get a dialog for 1st iteration, then it will store the path (see example)
Message 2 of 6
(6,996 Views)
If you want to write data inside while loop, then you must supply a valid filename to "write to spreadsheet" vi as write vi always ask user for filename when its "filename" input is emty (you can ask user for a filename using File I/O->Advanced->File Dialog vi BEFORE entering in a while loop OR - it's just simplier - use a shift register with emty path initialisation and pass it to write vi, and write vi output pass connect to output shift register).
If you want to write when all data have been acquired - i.e. after your while loop, than you must accumulate acquired data using a shift register (in your VI at the exit tunnel of while loop you have only data of the last iteration/acquisition, so only this data are saved). I'm changed a bit your vi,
so the data wiil be accumulated.
Usually, examles are the best explanations, so I've attached some.
Hope this helps.
Download All
0 Kudos
Message 3 of 6
(6,996 Views)
Thank you both for the answers!
Tell me if I have got this right now..
If I save to file inside the while loop, the data are written into the file on every aquisition.
If I use save to file after the while loop, the vi remembers the data until the while loop is ended. In my case that will be when I stop the vi, and then saves to the file.
Which method should I use? I have to run the vi for up to 30 minutes.
0 Kudos
Message 4 of 6
(6,996 Views)
If I save to file inside the while loop, the data are written into the file on every aquisition

yes - the data is written once every iteration of the loop. This is why "append to file" is wired true... the default is false, meaning the data will overwrite itself each time.

If I use save to file after the while loop, the vi remembers the data until the while loop is ended. In my case that will be when I stop the vi, and then saves to the file.

sort of - the data is written when the while loop exits, as it is waiting for the data. You will need to build up your data set, say in an array, inside the loop. Otherwise you will only write the data from the last iteration.
0 Kudos
Message 5 of 6
(6,996 Views)
Normally, if your data rate is not too high and for long-time acqusitions the approach when you save your data in a while loop works better because if something goes wrong (imagine - some OS problems), the data that has been acquired are already saved and will not be lost.
0 Kudos
Message 6 of 6
(6,996 Views)