From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Forming output of multiple cases of a case structure.

Solved!
Go to solution

I have a code where there are 32 cases in a case structure and 32 values for each case and the values keep changing when that case occurs again. I need to represent these 32 values in 32 outputs. My boss did it in a way with 32 global variables and store these values in these 32 global variables and then use these global variables to show those 32 values as output. I was hoping not to use global variables as i know it is wrong kind of programming. Can anyone suggest me a better method or using global variables is the best method and I should also do that. Can anyone help me what to do here. 

0 Kudos
Message 1 of 6
(2,596 Views)

You don't provide sufficient information. If each case outputs 32 values, does that mean you have 1024 values (32x32) ? Are these arrays with 32 elements? Do you have 32 values and each case changes one of them? What else is in each case?

 

How and where are these values used later?

 

Could you show us a stripped down and simplified version of your code as example so we can better understand (e.g. 4 cases with 4 values each)?

0 Kudos
Message 2 of 6
(2,588 Views)

Sorry for the lack of information. 32 cases each have one value. So there are 32 values over all. I tried making an array using indexing. But the problem is array keeps changing. That is these 32 values will not show up at once. One time it could be 5 values, another time it could be 12 values like that. My boss using global variable will set those values to that global variable. That is there are 32 global variables for 32 values. So if like number 3, 10 and 22 value appear then the corresponding global variable will have that value. Then next maybe 7,11,19, 23 and 31 came. Then these values will appear in their corresponding global variable and the other values of 3,10 and 22 will still be there until the next time either of these 3 values appear. So thats how it is to work. I did a stupid thing by using indexing and created an array. If i wanted array to work like the global variable then when 3,10 and 22 appear; i want values in array with inexes 3,10 and 22 and it stays there and the next time when 7,11,19,23 and 31 value comes then i want it to add to the existing array at indexes 7,11,19,23 and 31. Unfortunately the array doesnt work like that and I didnt remember that when I did the coding. As you know in my code during the first 3,10 and 22, the array will be updated to a 3 value array  and next when 7,11,19, 23 and 31 comes this 3 value goes and a new array with 5 values will come. So what should I do. Should I also put 32 global variables in those 32 cases like my boss did. Thanking You.

0 Kudos
Message 3 of 6
(2,563 Views)
Solution
Accepted by topic author govindsankar

Hi govindsankar,

 

As you know in my code during the first 3,10 and 22, the array will be updated to a 3 value array  and next when 7,11,19, 23 and 31 comes this 3 value goes and a new array with 5 values will come. So what should I do.

How do you we know code when you don't attach it?

Initialize the array to hold 32 elements. Keep the array in a shift register. In those 32 case you can replace elements in this array as needed.

 

Basically it's the same as I have shown to you in this post. You even accepted that as a solution!

Why don't you follow that advice?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 6
(2,560 Views)

@GerdW wrote:

Initialize the array to hold 32 elements. Keep the array in a shift register. In those 32 case you can replace elements in this array as needed


Chances are that you don't even need a case structure if you have some practical way to calculate the index of replacement. 🙂

Message 5 of 6
(2,549 Views)

Based on what you posted I don't think you should rely on your boss for advice on LabVIEW programming. As others have noted, this is very straightforward to solve using an array. Whether you need the case structure of not depends on what else is happening within those cases and what is driving the case selection.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 6 of 6
(2,540 Views)