From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Iterations of For Loops not working the same as the first iteration

I have written a program to analyze data from a large spreadsheet for my research. When I start the program, it asks me to select a file to analyze. I wanted to be able to run several files at once, so I put the code in a For Loop and made it so that I can choose several files at the start of the program. Then it analyzes one file at a time. However, only the 1st iteration of the for loop gives accurate data. The next iterations have accurate data until the end, where a bunch of it is either missing or jumbled. I don't understand how to fix it.

 

I triedchecking for race conditions by running it on "highlight", but it still did the same thing. The VI and all subVIs clear indicators when called and are reentrant, making a clone for each instance.

 

Any help would be appreciated!

0 Kudos
Message 1 of 8
(2,597 Views)

Hi KatelSyE,

 

How are you choosing your multiple files at the start? Could you put your various file paths into an array (outside the For Loop), then have the For Loop iterate on each path?

 

With regards to the jumbled data, would you be able to post your code up here, and even an example of how the data has been jumbled.

 

Thanks,

Josh E
Applications Engineer
National Instruments UK & Ireland
0 Kudos
Message 2 of 8
(2,594 Views)

Hi Josh,

 

The post-doc I work for wrote a program that allows you to select several files and puts them in an array of file paths and then it's fed into a For Loop, so each file is analyzed one at a time.

 

I can post the code, but it's pretty big with many subVIs and only works with our specific data output spreadsheets, so I would have to send all of it. Will that work?

 

Thanks

~Kate

0 Kudos
Message 3 of 8
(2,589 Views)

Yes a zip of the entire project would be helpful. 

Look for Uninitialized Shift Registers.  That is a likely culprit 


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 8
(2,583 Views)

@JÞB wrote:

Yes a zip of the entire project would be helpful. 

Look for Uninitialized Shift Registers.  That is a likely culprit 


I was kind of thinking it has to do with trying to replace array elements when the other files are smaller.  This would yeild old data left at the end of the array data.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 8
(2,573 Views)

Here is a zip file of the program and all the subVIs. The main program is "ExpandedAnalyzer (v4)" that runs the subVIs. There is also 3 sets of example data to try running with it. The problem only occurs if you run more than one file and you can see it either on the front panel under the last tab or in the results files that are created after the program has run.

 

Thanks for your help!

 

~Kate

0 Kudos
Message 6 of 8
(2,528 Views)

Hi Katel,

 

the first (real) problem is to load all files at the beginning and putting their contents into a big 3D array. Your files have different sizes so you will have empty elements in your 3D array (maybe a lot of them)...

 

Then all of your code needs to be refactored. On my laptop most VIs span several times the screen size - I will not even start to debug something in there!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 8
(2,522 Views)

You have a TON of code that is just being copied.  Make subVIs!  You could reduce that main VI quite a bit just by making subVIs.  And you might uncover some of your bugs as well.  Because it is a lot easier to debug a small VI than the ginormous main VI you have there.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 8
(2,481 Views)