LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I make a dialog box with an OK button start with the button not pressed? Also, a related question: why are sequences/locals not good?

Hey, I've got a sub-vi that closes when you hit OK. The problem is, the second time it is invoked, it is already down.

I know that by changing it to "latch when pressed" it works fine. But for educational purposes, how would I set it upon being called?

I know one way is to use a sequence and in frame 0, have a local variable of the OK control set to write and send it a true. Then in frame 1, have the normal loop.

However, I've seen that a lot of experienced labview programmers don't like using local variables or sequences, but rather controlling via data flow and references. Why is this a superior technique?


How would one do the above asked about button setting without local variables or sequences?

Thanks!

-Dobbs
0 Kudos
Message 1 of 7
(3,470 Views)
I will supose that your popup window is a subVI. In that case, just make your button an input parameter, and wire it as false, everytime the vi is executed, a false value is passed to it, and you don't need a latch when pressed or local variable. Most people doesen't like them because they break data flow, and can create unexpected behaviours, as race conditions are. One reason to not like the sequences is that they hide the code, and debugging and program visual understanding is worse.
Hope this helps
0 Kudos
Message 2 of 7
(3,470 Views)
There are 2 ways that I would do this. One is similar to what you have described.

When your program is ready to end, (I'd imagined that you have a WHILE loop and the user presses the button to stop), I pass a data from the WHILE loop into a sequence structure. Inside this single structure, I have the local variable that is wired to FALSE. This way, there is always some sort of dataflow and you can control the dataflow.

The second method does not use a local variable but uses a Property Node. You can access the value of the button from "Value". Wire it to FALSE when your program ends. Unlike the earlier method, the property node, by default has "Error In and Error Out" that you can wire to control the data flow.

Dataflow gives you an idea on how the program is ex
ecuted so you know what happens in your program. Without data flow, any parts of your program can happen and this will be impossible to debug if you have a big program.

I seldom use sequence structures because I wire most of my Error In/Out so my program has some form of data flow. However, I still use sequence when I have to.

I hope that answers your questions.

Shan Pin Koh
0 Kudos
Message 3 of 7
(3,470 Views)
1. Try 'Switch until released'. Be sure you set this mechanical action while the OK button is in the 'un-initialized' state, then you'll run ok.
2. I would imagine that for every programmer who doesn't like locals, etc., there is another who does. Its a matter of preferences and style.
In non-labview languages, constants and calls to config files equate to Labview's use of locals, globals, and sequences.
Also, a 1-time running Sequence, set before a while loop of your main program, can act as a call for config files or setting front panel properties to their initial values.
Bottom line, there are many ways to get the job done, just be consistent.
Good luck, Doug
0 Kudos
Message 4 of 7
(3,470 Views)
I forgot to attach a quick demo of what I mentioned above...the OK button will always begin in the unititialized state and does not require sequences or locals.
0 Kudos
Message 5 of 7
(3,470 Views)
Its not like locals and sequences should never be used but I try to use them sparingly. The problem with locals is that race conditions can easily occur. I don't like sequences because most of the time they're not needed and when used, they tend to hide code. I'd rather have my diagram a little bigger but be able to see everything at once. In your example, all you would need to do is wire a constant to the local variable and also wire it to the outside of the while loop. You've then created a data dependancy without hiding part of the diagram. If there are a lot of variables that need initialization, what I do is put them all inside a single sequence structure and then wire a single element to my main loop. Another thing that I've done is modify those LabVIEW fun
ctions that don't have an error in and error out connection and add them in a new VI so that it is easier to enforce dataflow. All of this, of course, is just my opinion.
0 Kudos
Message 6 of 7
(3,470 Views)
Make sure you are selecting the button "OK" or "STOP" from the control palette. They already work the way you are expecting.

Check the following answer, especially the attached example, that I provided to a similar question:

http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=50650000000800000008190000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0

Best regards;
Vargas
www.vartortech.com
0 Kudos
Message 7 of 7
(3,470 Views)