LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Increment variable without while loop

Solved!
Go to solution

Hi,

 

I am searching a way to add one to a variable each time a Boolean button is pushed without using a while loop. Because i need to use the variable each time and the same boolean button is used to do other tasks.

 

Do you have a solution?

0 Kudos
Message 1 of 8
(5,113 Views)

How do you plan to distinguish "Push Button to Increment" from "Push Button to do other task"?  Are you planning to write a large LabVIEW routine without loops, maybe as a Frame Sequence with 100 Frames?  [An extremely bad idea, by the way -- you should almost never need a Frame Sequence, and should look for places to use Loops].  Here's a related question -- without using a Loop, how can you tell a Boolean has not been pushed?  And what is the meaning of "not" -- does it mean "at this exact time that I'm testing the value of the Boolean", does it mean "is the Boolean True", does it mean "is the Boolean False", does it mean "is the Boolean different than it was at some earlier time in the program, suggesting it has been changed an odd (but not necessarily once) number of times?

 

There may be a way to do this, but it will probably be complex, difficult to understand, and (therefore) a Bad Idea ...

 

Bob Schor

0 Kudos
Message 2 of 8
(5,109 Views)

@Lea.R wrote:

Do you have a solution?


No! There is no solution because the question makes no sense!

 

What is a "variable"? Define "use"! Define "other tasks"! What is your program architecture?

 

Every toplevel program has a while loop. Every single one of them! (I hope you are not using the "continuous run" button).

 

A good idea to actually get help is to attach your code and explain exactly how you are using it, what typical controls values are, and what you expect to happen as a function of user input. So start with that. Thanks!

0 Kudos
Message 3 of 8
(5,091 Views)

All code intended to run until the something says "stop" needs some kind of loop.  In text coding, it's often a "Do While" loop, or "Do Until" something happens.  It's no different with LabVIEW.  You need some kind of a loop to keep it going round n round until something tells it to stop doing that.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 8
(5,083 Views)

Based on your question it's a bit unclear what you really want.

 

As was explained by Bob Schor, in order to know that a boolean value has changed, you fundamentally need to check it twice (i.e. is it the same as before?). If you want to check for changes in a control, a good way to do this is to use an Event Structure - these prevent you from having to check a value many times when it doesn't change, and 'immediately' alert you once it does.

 

To evaluate how to best fulfill your needs, especially with regards to "the same boolean button is used to do other tasks" - we really need to see some code. What are these tasks? How is the button "used"? Do you have some other loop already (and you're trying to avoid a second loop - that seems plausible)?


GCentral
0 Kudos
Message 5 of 8
(5,076 Views)

Use an event structure within a while loop to respond to all of your front panel interactions.  In the event case for the specific control you are trying to act on, you can either perform actions directly, or (preferably) enqueue appropriate states in a queue for processing.  I like to use a queue with a datatype which is a cluster containing an enum (containing the case to execute) and a variant (which can contain any type of data to be converted later).  Then, in a separate processing loop, you dequeue an element from that queue if it exists, unbundle the case to execute and wire that to a case structure (your state machine), and then within that case you can convert the variant data appropriately and act on it.  This gives you the power to enqueue multiple states as appropriate to the code you want to execute for any given event.

 

In your case, regardless of whether you put this code in the event case or in a case within your consumer loop / state machine, you want to read the count from some sort of variable or control, increment it, and then write it out again.

0 Kudos
Message 6 of 8
(5,039 Views)
Solution
Accepted by Lea.R

I suggest that you use an Event Structure. In the Event for the button, use a Feedback Node to create a counter.

----------------------------------------------------------------------------------------------------------------
Founding (and only) member of AUITA - the Anti UI Thread Association.
----------------------------------------------------------------------------------------------------------------
0 Kudos
Message 7 of 8
(5,018 Views)

I am using that. I thank you 🙂

0 Kudos
Message 8 of 8
(4,994 Views)