05-10-2019 09:41 AM
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?
Solved! Go to Solution.
05-10-2019 09:58 AM
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
05-10-2019 10:25 AM
@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!
05-10-2019 10:35 AM - edited 05-10-2019 10:36 AM
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.
05-10-2019 10:57 AM
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)?
05-13-2019 12:23 PM - edited 05-13-2019 12:30 PM
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.
05-13-2019 05:06 PM
I suggest that you use an Event Structure. In the Event for the button, use a Feedback Node to create a counter.
05-14-2019 03:07 AM
I am using that. I thank you 🙂