Jump to content
News about the LabVIEW Wiki! Read more... ×
mthheitor

Programmatically select all boolean (best way to avoid race condition)

Recommended Posts

Hello :)

 

The attached code will select all boolean from my VI and get the value of each one. Then build a array of boolean that will be used in another VI.

My doubt is about the order of the boolean. In my example there four boolean: 1) "Home", 2) "Ensaio", 3) "Análise" and 4) "Configurações".

How can I ensure the order of the boolean inside the array?

I mean, if a user delete the boolean named "Ensaio" (2nd element of the array) and add another one, it will be the second element of the array or will be last one?

 

Note 1: I'm using this code because the other users will add or remove boolean from the Front Panel, and I don't want them mess around with the block diagram.

Note 2: Each boolean is customized, having different images each one.

 

 

captura.PNG

Share this post


Link to post
Share on other sites

An indicator has two "labels". The label and caption.

Show the caption (should be defaulted to the same as the labe and hide the label). Then rename the controls to 1_Home, 2_Ensaio etc (The caption will be what the user actually sees without the numbers).

Now you can get the label name, split off the number and put it into a cluster with the value (if you have less than 10 controls, you don't need to convert to a numeric). Make sure the number is the first item in the cluster because LabVIEW will automatically sort on the first element so you can use the sort array directly. From there you can sort the cluster and now you know your clustered booleans are in numerical order.

Share this post


Link to post
Share on other sites
6 hours ago, mthheitor said:

My doubt is about the order of the boolean. In my example there four boolean: 1) "Home", 2) "Ensaio", 3) "Análise" and 4) "Configurações".

How can I ensure the order of the boolean inside the array?

I mean, if a user delete the boolean named "Ensaio" (2nd element of the array) and add another one, it will be the second element of the array or will be last one?

The method you invoke on the Panel reference always returns the Controls in the order that they were created.

aka. If you delete the second element and create a new one (even with same label), it will be added to the end of the list. 

Share this post


Link to post
Share on other sites

I believe they are in the reference array according to the tab order
You either have to know the names in advance or carry their names with their values.

Get Value.png

Edited by infinitenothing

Share this post


Link to post
Share on other sites

to the OP: Be mindful that the "Traverse for GObjects" serves the array in the reverse order from Panel:Controls[] method, probably because of the way it stores the references in the recursion loop.

@infinitenothing You're totally right. Tab order it is, with newly created controls added at the end of the list.

Edited by Francois Normandin

Share this post


Link to post
Share on other sites
6 minutes ago, mthheitor said:

 

 

@Antoine Chalons didn't know this traverseref.llb. Think I will use it in the future. Thanks.

You are welcome, this llb is indispensable for scripting and can also help for UI management ;)

Share this post


Link to post
Share on other sites

So a while ago I wrote a XNode that would add functionality to the traverse for GObjects.  One thing it would do is order the references based on their positioning on the front panel or block diagram.  The most common use for me was for something like a grid of buttons.  I would want them ordered from left to right and top to bottom so I made an enum input to the XNode that orders them after finding them.  It would also return the reference as a boolean so no casting was needed after.  Of course this goes with the normal "XNodes are experimental" statement but you could look at the code and see how I did it if you wanted to not use it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site, you agree to our Terms of Use.