LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

for loop nested within a while loop

Solved!
Go to solution

I have written a data logging VI to get data from a DAQ, then write it to a spreadsheet. This worked fine. What I am trying to do now and am having trouble is to place that vi within a while loop that will automatically write a new file name after the For-loop finishes its iterations. In a text based program when the for loop finished I would just send it back to the while loop for it to write the new file name and then execute the for loop data collection and spreadsheet writing iterations.  Below is the general outline of the operations of the program.

 

Establish file name and path based on while loop iteration (eventually this will be the current date and time)

 

run for loop for specified iterations:

     read DAQ

     write data into .csv spreadsheet

 

When specified iterations are over:

     writley new file name

     run for loop again

 

repeat until stop is pressed

 

What is actually happening is the file name and path are established, the for loop runs through its iterations but only writes the last set of data and then the program stops.

 

any ideas?  Program attached

0 Kudos
Message 1 of 6
(3,013 Views)
Solution
Accepted by topic author tetanus

Don't know about the program stopping. I replaced the methods with a random number generator and everything seemed work okay after setting the Write to Spreadsheet to append instead of creating a new file each time.

 

p.s. cleaned the wiring to make it readable - neatness counts.

Message 2 of 6
(3,005 Views)

Dennis,

Much nicer, thanks. I had a couple problems there. Append to file was critical for writing to the same file each time the loop iterated. The rest was a little structure and house cleaning. The diagram looks much more easy to read.

That is basically what I needed to do. Eventually I would like to write a new file each day so I think I would need to change the number of loop iterations to a while loop that stops when the date changes.

Thanks so much for the help!

0 Kudos
Message 3 of 6
(2,984 Views)

I tidied it a little further and compressed the wiring, no use to read those channels one by one and then convert one by one, those things always belong in a loop. 😉

(and i like tight vi's, feels less bloated and more to the point ... more C# (if you forgive my textbased referrence))

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 6
(2,968 Views)

 

 

  • Since you want exactly four channels, I don't see the need to read the number of channels.
  • You don't need a separate indicator for the data, you can use the digital display of the chart (simpler diagram!)
  • The loop iteration control should be inside the while loop, else you cannot change it during the run.
  • I would place the stop in the innermost loop, else it might take a long time to stop.
  • The stop control should be latch action.
  • ...

 

Message 5 of 6
(2,958 Views)

That's even better. Works like a charm and much more elegant than my original code. Didn't know about the digital out from the chart. Makes sense.

 

Now I just need to get it to write a new file each day. I have been looking at some of the posts here and trying to understand how to adapt example to my purpose.

 

Thanks to all of you for your help. This site is an amazing resource. I would have banged my head against the wall for days to achieve this.

0 Kudos
Message 6 of 6
(2,944 Views)