12-27-2012 11:06 AM
Can I reset a control button programmatically? Specifically, I'm wanting to switch a Boolean button back to a false state in response to certain events/conditions.
For example, consider the attached VI. (It is un-finished, because I don't know how to finish it.) The user can make the counter count by clicking the count button. What I want to do is stop the counter at some number (10) and reset the count button, so the user has to re-click for a new count.
Solved! Go to Solution.
12-27-2012 12:11 PM - edited 12-27-2012 12:23 PM
also, change the mechanical action of the count switch to "latch when pressed or released"
12-27-2012 12:33 PM
Check out "Create... > Local Variable"
12-27-2012 01:31 PM
@tomlawton wrote:
Check out "Create... > Local Variable"
...and then DON'T create one. Check out Apok's example instead...
12-27-2012 01:38 PM - edited 12-27-2012 01:38 PM
I think he wanted the "Count" button to remain pressed in- and the counter to keep counting- until n=10, or whatever- and then have the count button pop back out. In which case, I think he'll want a local...
(Might be wrong of course..!)
12-27-2012 01:38 PM - edited 12-27-2012 01:41 PM
This is one of those times some additional functions can be your friends.
Events, Property nodes and Feedback nodes should be loaded into any developer tool-box ready to replace the "Screw-Hammer" when a better tool exists.
Count Value change event selects either -1 or 100 for timeout
Stop value change sets the exit condition
I renamed Count (I32) to Counts since its not very good to have two objects with the same label
EDIT:
I think he wanted the "Count" button to remain pressed in- I read that too since the true string is "Counting" Still the Local is less desirable since a Val(Signalling) can be beneficial in this case
12-27-2012 02:14 PM - edited 12-27-2012 02:14 PM
@tomlawton - That is exactly what I'm wanting.
12-27-2012 02:30 PM
In that case, right-click on your "Count" button terminal, "Create...> Local Variable". That gives you a "second terminal" to your front-panel control... which you can either read from, at a different place on the diagram (sometimes saves messy wires), or in your case, you can change it (with a right-click) to write mode , thus allowing you to force a value to your front panel control.
BUT- huuuuge BUT!- be careful! Use of locals can give rise to race conditions, and all manner of bad things. (Additional copies of data is a common refrain, which would be heinous for a big array, but acceptable for a single boolean). Plus they tend to elicit strong reactions among programmers; along the lines of Dijkstra/ GOTO...
12-27-2012 02:33 PM
i believe that Jeff's would be a better solution....
12-27-2012 02:37 PM - edited 12-27-2012 02:40 PM
Undoubtedly- though I have only read the code, not run it (to paraphrase Knuth)
However, it's nothing like as transparent for a beginner to comprehend; and while we should encourage good habits (and discourage bad!), we don't need to intimidate.. 😉 (or optimise prematurely ;-D)