LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically choose boolean to write in cluster

Solved!
Go to solution

Short version:

I want to write and read the status of a boolean in a cluster by name, but i want to choose which boolean programmatically. 

SydneyAVDE_0-1739268414264.png

 

Long version:

I've been searching and trying for many hours but i feel i'm missing something obvious and i'm stuck in a loop. No pun intended.  

 

The reason behind this is that i can program one loop that adapts itself to a source. Meaning, when i press 1 button, lets say "button A", the loop knows what to do for everything in the program with the name A.

 

I've tried many things like working with property nodes and variants etc.. while writing this question, i figured the property nodes out, sorta. I wonder if there is an easier way. 

SydneyAVDE_2-1739273621062.png

 

Many thanks in advance to anyone who can solve my issue.

I know i can always get rid of the cluster and do things easier (yet bulkier), but i have to know if and of so, how it is possible. 

0 Kudos
Message 1 of 15
(378 Views)

Update

I am now trying arrays:

SydneyAVDE_0-1739276364846.png

 

0 Kudos
Message 2 of 15
(359 Views)

I might be misunderstanding your needs, but just use a case structure?

NIquist_0-1739288654717.png

 

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
Message 3 of 15
(325 Views)
Solution
Accepted by topic author SydneyAVDE

(You are leaving out a lot of  details, but I cannot open LabVIEW 2024. Consider "save for previous, 2020 or below before sharing)

 

 

A cluster is a datatype that cannot change at runtime, so getting the label text with every iteration is silly. That belongs before the loop!

Does the cluster only contain booleans or can there also be other element types? If this is just a collection of boolean, I would maintain it as a 1D array in a shift register. No need for local variables. Conversion to cluster only needs to be done for display.

 

altenbach_0-1739290745176.png

 

Overall, this seems all rather silly. Can you explain the overall purpose of this jumping through all these flaming hoops?

I am sure there are significantly better ways to do whatever you need to do, just take a step back first instead of digging an even deeper hole.

 

Message 4 of 15
(316 Views)

@NIquist wrote:

I might be misunderstanding your needs, but just use a case structure?

NIquist_0-1739288654717.png

 


Yes this is the easiest to understand solution and i was considering taking the step back to a simple case structure. But this meant making a single case for all 20+ boolean. My plan was to extract the name of the button that was pushed, and use this to adres the appropriate boolean.

 

This way i would only need 1 loop for all 20 situations.

0 Kudos
Message 5 of 15
(275 Views)

@altenbach wrote:

(You are leaving out a lot of  details, but I cannot open LabVIEW 2024. Consider "save for previous, 2020 or below before sharing)

 

 

A cluster is a datatype that cannot change at runtime, so getting the label text with every iteration is silly. That belongs before the loop!

Does the cluster only contain booleans or can there also be other element types? If this is just a collection of boolean, I would maintain it as a 1D array in a shift register. No need for local variables. Conversion to cluster only needs to be done for display.

 

altenbach_0-1739290745176.png

 

Overall, this seems all rather silly. Can you explain the overall purpose of this jumping through all these flaming hoops?

I am sure there are significantly better ways to do whatever you need to do, just take a step back first instead of digging an even deeper hole.

 



I like this option and this is probably what i was searching for.

 

I got the idea from some of my previous work:

SydneyAVDE_0-1739342910811.png

SydneyAVDE_1-1739342927184.png

SydneyAVDE_2-1739342937289.png

 

The idea was that there would be one dynamic loop, which adapts to a choice made by the user, instead of a case structure with many cases.

 

For instance:

• Button with label C has been pressed:

loop trough all boolean

→ Set boolean 1 and 2 TRUE

→ boolean C found set status of boolean C TRUE

• Button B pressed:

→ loop trough all boolean,

→ Set boolean 1 and 2 TRUE

→ boolean B found, set status of boolean B TRUE

 

It seemed so obvious to me that labview would have a function inside clusters, where i could just easily  select the boolean as you can with context menu:

SydneyAVDE_3-1739343835391.png

So that's why i asked.

 

What if there would also be other elements than booleans? Would this still work? 

0 Kudos
Message 6 of 15
(269 Views)

This all still looks extremely convoluted. Please attach code instead of pictures. Don't forget to "save for previous".

 

Why have two sequential for loops if one could do the job? Why the local variables? Why the convoluted Boolean logic? Why call it radiobuttons. (That terminology typically means that only one can be true at any given time and it is not obvious if that applies here.)

0 Kudos
Message 7 of 15
(258 Views)

Please don't get the multiple programs mixed up. The radiobuttons and keyboard are not applicable to the original question. They where merely story based examples of where i got my inspiration from. I will upload the radiobutton examples tomorrow, purely for educational purposes, because i personally felt this was an advanced and good solution to something that was hard for me to program. 

 

Why have two sequential for loops if one could do the job?

If you're referring to the radio button example, I think I did that because otherwise, the label of the previously active button would be read instead of the newly activated one. Then again, I could probably just use NewVal. I'll confirm this tomorrow.

 

0 Kudos
Message 8 of 15
(238 Views)

@SydneyAVDE wrote:

If you're referring to the radio button example, I think I did that because otherwise, the label of the previously active button would be read instead of the newly activated one. Then again, I could probably just use NewVal. I'll confirm this tomorrow.


That statement makes no sense! You are operating on the same reference in both loops.

 

I don't understand the exact requirements, but to act on properties of the changed element (that triggered the event), here's a code skeleton that you probably could adapt to your requirements. (I am sure changes are needed, I am only shown the general logic)

 

altenbach_2-1739383356634.png

 

 

 

As said before, I am sure once you attach some simplified code of the problem, we could give more targeted advice.

 

0 Kudos
Message 9 of 15
(209 Views)

As said before, today i will upload the code. Here it is. (saved in v20.0)

Functionality: only 1 button may be active, print last activated labelname into string.

 

I am sure this could be way more efficient. 

0 Kudos
Message 10 of 15
(153 Views)