LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

passing counter variable between loops

Solved!
Go to solution

I have a question about passing a counter variable between different event/while loops and having the value increment regardless of which loop is initiated. 

 

The basic problem is that I am writing unique filenames to for data collected on a spectrometer, and I would like the value at the end of the file name to increment each time I collect the data. There are several different ways I have can collect the data, and I would like the counter to increment when any of the collections is triggered. The attached file shows basically what I am trying to accomplish. The collect buttons represent two different types of data I collect from my instrument, but the counter variable isn't passed correctly between the two loops. Is there any way I can get the counter to increment so that both loops see the same counter value?

 

Thanks for your help.

 

Micah

0 Kudos
Message 1 of 6
(3,422 Views)

Use an Action Engine.  If you aren't familiar with them, search the forum for "Action Engine".  Specifically look for Ben's nugget -- it's terrific!

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

You should use action engine.  See attached.  While trying to change your code as little as possible.  I did the following:

 

1. Created CNT.vi action engine.

2. Fix the sticking key problem that you were having (one button press register multiple events) by changing the event to mouse down.  I don't know the problem happens, but it does for your program. 

3. Add a time out case for both event structure.  With your design, you can't stop the loops properly without the timeout cases.  You will have stuck without the event structures.  Unless you have a really good reason to use two event structure, try to stick with one. 

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
Download All
Message 3 of 6
(3,412 Views)
Solution
Accepted by topic author realcomfy
I cannot look at your code since I am on a phone. But you really should only have/need one event structure in a vi. The only exception I can think of is one to handle user events and one for GUI events. But even then there is no reason I can think of for needing two.
=====================
LabVIEW 2012


0 Kudos
Message 4 of 6
(3,404 Views)
Edit - after reloading I see that it was already suggested to use only one event structure 🙂
=====================
LabVIEW 2012


0 Kudos
Message 5 of 6
(3,402 Views)

After a moment of reflection I realized you were completely right. This has made my actual code much cleaner (the code I posted was only an example of the problem I was working on). THanks!

0 Kudos
Message 6 of 6
(3,367 Views)