01-24-2019 08:21 AM
I think there's a more elegant way to do this with the Feedback control but I can't get it to work.
Solved! Go to Solution.
01-24-2019 08:51 AM
Note 1: There is a decrement function; so you could subtract 1 without an explicit constant.
Note 2: The Delete From Array removes elements from the end if no index is specified.
You could do something like this:
But the simplest form would be:
Paul Cardinale
01-24-2019 09:03 AM
How does it not work?
Please attach an actually VI of your non-working attempt rather than a screenshot of the original code.
01-24-2019 09:43 AM
Thank you. The simplest version worked great!
01-24-2019 09:46 AM
It does work as it is. I just thought I could use a Feedback node somehow instead of the 2 local variables. This is just a part of a larger vi that I don't wish to share plus I thought it was simple enough to just show a photo.
01-24-2019 10:32 AM
The more elegant - or more dataflow-ish - way to do this is to replace those local variable with wires from the control itself. I am even a bit afraid to think about code where using local variables in this way was necessary.
01-24-2019 12:14 PM
@RHutchings wrote:
It does work as it is. I just thought I could use a Feedback node somehow instead of the 2 local variables. This is just a part of a larger vi that I don't wish to share plus I thought it was simple enough to just show a photo.
Yes. But you said you tried an alternative with a feedback node that didn't work for you.
If you want help troubleshooting your alternative, then it would help if you posted that attempt.
01-24-2019 12:34 PM - edited 01-24-2019 12:36 PM
We really need to see the entire code to give more constructive advice. Local variables completely blur the distinction between control and indicator, we cannot tell what it is!
Is it a control where the user can manually change values at runtime? Is it a useful indicator that displays information? Is it a useless (even hidden) control/indicator for the sole purpose of data storage via locals?
For the third case, the data could exclusively live on the diagram (wires, shift registers, feedback nodes) and the front panel object could be deleted entirely. This is most efficient.
01-24-2019 12:45 PM - edited 01-24-2019 12:47 PM
That sounds great but doesn't work for me. There's reading and writing and this is the only way I know to do it. Here's the whole thing if you want to help me.
01-24-2019 12:59 PM - edited 01-24-2019 01:00 PM
I still don't see your failed feedback node attempt.
A couple things I see:
1. I don't see any while loop in this VI. So it seems to run once the stop. Is that what you want?
2, Event structures just about always belong in a while loop. Write now, if you don't hit Load Setup 2 in the first 100 milliseconds after you start your VI, that event structure times out to never have a chance to run again.
3. Too many local variables. Rather than read from a local variable, you should be using the wire from another location. Then you can get rid of the sequence structure. The other problem is that they cause race conditions. Current(V1-V2) is written to at multiple locations. Which value sticks depends on what section of code runs last.
4. If you do need a sequence structure, then a flat sequence is better than a stacked for readability.
5. Index Array is resizable. Drag the bottom border down. You'll get indices 0 through N automatically.