Showing results for 
Search instead for 
Did you mean: 

Is there a way to modify a single value of an array without rewriting to the other elements?


With a cluster, I can use the "Controls[]" property node to get a reference for any control in the cluter and then write to that value by using an additional "value" property node.

Is there a way to do a simialr thing with an array?

I have tride using the "IndexVals" property node, but if I change any of the other array elements through the front panel while the code is running it breaks.

Basically I want to programatically change the value of one element but still be able to change the values of of other elements on the front panel.

0 Kudos
Message 1 of 18

There is no need to do it the way you describe, rethink what you really is trying to achive.


You could for instance keep the array in a shift register in a while loop.

Have a event structure with a short timeout inside the while loop. Make changes to the array in the timeout case and display the array. Catch user interaction with the array in the event structure and read back the array to your shift register.


Or something to that effect, depending on your needs.

0 Kudos
Message 2 of 18

Replace Array Subset will modify the vaue or values of an array that you specify by the index inputs.  No need for property nodes unless you need to modify a control - and you should be very careful if doing that to avoid a poor user experience.



0 Kudos
Message 3 of 18

To update a array control, even if only a single value changes, requires the entire array to be written (e.g. via a local variable). This is not a big deal, because I assume that the array is pretty small (else it would not make sense to have it as a control!) Just rewrite all the other values to what they already are. (Updating all array elements using a local variable is probably orders of magitude more efficient that updating a cluster element via a reference and property node.)


Maybe you should describe in more details what you are actually trying to achieve. Controls are typically used for user input, so programatically changing them often leads to poor user experience, e.g. if the code is fighting with the operator for control of a value.


Can you explain your usage case, maybe attach a simplified version of the code?

LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 4 of 18

So I have tried this many ways with the array and am having the same issue each way I try it. This is my latest attempt.

If you run the VI I have attached you will see the basic operation I am expecting. As the line scrolls through the array of bools, they turn off momentarily (to indicate they have been "read") then they are returned to their previous value. I want to be able to change any other array element at any time. I don’t care if the one where the line is (that I am actively controlling) misbehaves if the user tries to change it while its actively being modified by the program.

The issue I am having Is that for whatever reason sometimes if I modify another array bit while the program is changing another, it either fails to turn off the one being prgramatically changed, or worse fails to turn it back on.

I am guessing there is some sort of race condition happening but I can’t see where.

(I quickly and repeatedly toggle one bit to occasionally see the undesired behavior)

If I hit a button while it is in another event, it should still trigger when it comes out of that event right? The events queue up correct?

I don't see this behavior if I use a cluster and modify the values by reference. I want to avoid this for several reasons including the efficiency penalty that .

0 Kudos
Message 5 of 18

The things here are not 100% clear to me (yet), it is still very early Smiley Happy Neither I understand why you need this kind of "animation". However, I would point out some possible problems when you use Event structure:

  • It is always adviced to have any control inside their corresponding Event case. Your Boolean array, and that hidden Boolean control are both outside their event cases.
  • Do not use a hidden control as a variable to store information. This is always a sign of "design went havoc".
  • You should not use that Val(Sgnl) property node on that hidden control. I feel uncomfortable with that. If you need to trigger a certain Event case, use Dynamic User Events, so no need for that hidden control approach.


0 Kudos
Message 6 of 18

OK, here's a quick draft how you could do it (LabVIEW 2013). Notice that this is now done with much less code. (no event structure, no hidden controls, a single case structure, not even a shift register. A single local variable, pleasant dataflow, easy to debug, etc.)


See if it can give you some ideas. It would be easy to modify for the exact desired behavior, just try it!

LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 7 of 18

0 Kudos
Message 8 of 18

@teshurtz wrote:

For simplicity, my code just inverts the currest state, so if you want something different, it would be trivial to do. If you click the boolean during the time it is changed, it gets inverted to the opposite it was just changed. What else would you expect as correct behavior?

The problem is that you overload the information content of the array, having to hold both the values and temporary opposite values in a single boolean. All you probably need is another shift register holding state information.


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 9 of 18

sorry I tried to be clear but I guess I wasn't. It is not the element I am clicking that behaves incorrectly. It is the one that being prgramatically changed. E.G. if all bits are high and I am toggling bit 17, as it scans through bit 5 and sets it false. then for whatever reason it does dot get set high (on the "30" case). 

This was what I was trying to fix by adding events and such. I am perfectly OK with the bit behaving erratically if I click it when the line is on top of it, but I don't want bit 3 to change funny if I am modifying bit 15.


Does that make sence?

0 Kudos
Message 10 of 18