LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

file I/O write to spreadsheet file vi

Hi there,

 

     the write to spread sheet file VI is inside the for loop. How can I generate a new file and save the data for each loop?

 I tried the " append the file (new file, false) option, but it didn't work.

 

Thanks,

 

Lei

 

0 Kudos
Message 1 of 16
(4,938 Views)

Hi - are you looking to create a new file on every iteration of the loop or create a single file and log the data on every iteration?

 

If you want to create a new file on every iteration you need to supply a new file name each time.

 

If you want to add the data to the same file on every iteration simple set "append to file" = TRUE

 

If this doesn't work post your code and we can take a look

 

David
www.controlsoftwaresolutions.com
0 Kudos
Message 2 of 16
(4,921 Views)

To create a new file each iteration of the loop, you must change the file name on each iteration.  you can do this by appending the loop iteration number to the end of the file name as shown below:

 

UniqueFilename.png

 

- tbob

Inventor of the WORM Global
Message 3 of 16
(4,917 Views)

Thanks guys for the reply.

 

 I attach my program here. My application is scanning the spetrometer for several times and save the data separately. so I need a new file for every scan. Another thing is that I am not very sure to put the file I/O inside or outside of the For loops.

 

  Lei

 

 

0 Kudos
Message 4 of 16
(4,910 Views)

You Path variable is always the same.  You will only create one file, and it will be overwritten each loop iteration.  You will lose all previous data.  Two things you could do:

 

1.  Do what I showed you, change the file name (Path) with each loop iteration.  Then you will have a bunch of files with the data.

2.  Instead of creating a new file each loop, just append the data to the file.  Each 2D array of data will be appended to the file.  If you do this, it would be nice to have a separator line, maybe a line of all 0's, to separate the data by loop iteration.  This is just an option.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 16
(4,906 Views)

Hi tbob,

 

    you are absolutely right, when I run the program, there is only one data set in the file.

 

    But how to do your second  option? I change the append to file into TRUE, it has the same output with false.......

 

 

   lei

 

0 Kudos
Message 6 of 16
(4,902 Views)

How many loops are being run (# scans)?  If it only runs one loop, the outputs will be the same.  If it runs multiple loops, the data should append at the end of the file for every loop iteration.  Your default value for # scans is 0, which means the loop won't run at all.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 7 of 16
(4,898 Views)

Thanks tbob,

 

   the # of scan is changable on the front panel,typically I would set it as 10. I run the program but still there is only one set of  data in the file

 

 

   Lei

0 Kudos
Message 8 of 16
(4,893 Views)

maybe i have to use shift register for the # of scan loop?

 

0 Kudos
Message 9 of 16
(4,883 Views)

Use the execution highlite tool (the light bulb).  Watch what happens.  The Write to Spreadsheet file should execute 10 times, once for each scan loop.  Put a probe on the data input to the Write function.  See what goes in.  This should match what is written.  Maybe you have no data after the first scan.  Pause the program after each write, open the file and look at the data.  Then close the file and continue the program.  Let me know what you see.

 

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 16
(4,876 Views)