NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
realcomfy
Posts: 5
0 Kudos
Accepted Solution

passing counter variable between loops

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

Active Participant
DianeS
Posts: 585
0 Kudos

Re: passing counter variable between loops

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!

Active Participant
jyang72211
Posts: 1,332

Re: passing counter variable between loops

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!
Trusted Enthusiast
SteveChandler
Posts: 2,249
0 Kudos

Re: passing counter variable between loops

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


Trusted Enthusiast
SteveChandler
Posts: 2,249
0 Kudos

Re: passing counter variable between loops

Edit - after reloading I see that it was already suggested to use only one event structure :smileyhappy:
=====================
LabVIEW 2012


Member
realcomfy
Posts: 5
0 Kudos

Re: passing counter variable between loops

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!

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page