LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to illiminate some local variables

Each supply has 2 elements, a before and after. So there are anywhere from 2 to 8 measurements depending the number of supplies.

0 Kudos
Message 31 of 43
(1,864 Views)

@altenbach wrote: 

Since the array elements for one supply are not adjacent, would you get one array with three elements if there is only one supply, discarding the second element? I asked for example arrays for 1,2,3, 4 supplies. Please give examples.


I'm confused because the original code showed the elements for each supply being adjacent and now the elements are not adjacent.  I think some time needs to be spent deciding what are the requirements, before any code is written, so that people trying to help you out aren't wasting their time.

aputman
0 Kudos
Message 32 of 43
(1,861 Views)

While the suggestions on how to handle the data in the array are valid I want to back up and address the topic of this thread... eliminating Locals.

 

What I have seen in the code screams "Action Engine" because there is data that needs to be touched from different parts of the code and the result available in multiple places.

 

For each of the operation related to the data set that need to be performed implement an Action associated with type interaction with data. Init, Update, Evaluate, Get Updated ...

 

The suggestion that have been provided before this post give you option on "How to do" what needs to be done to the data, the Action of an Action Engine tell you "where to do it".

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 33 of 43
(1,859 Views)
0 Kudos
Message 34 of 43
(1,852 Views)

You attached an empty VI. Can you attach the code shown in the picture instead?

0 Kudos
Message 35 of 43
(1,850 Views)

This should be the one.

0 Kudos
Message 36 of 43
(1,846 Views)

Try this. You get an array of supplies.

 

differencer2.png

 

Some of your subtraction are reversed, so I am not sure what's the right way, so swap the input to the subtraction as needed.

0 Kudos
Message 37 of 43
(1,841 Views)

If you look closely at the wiring, you'll se that the second wire of the first subtract vi moves down once per supply added and the first of each supply is perfectly sequential.

 

The code I show works and I could just put into a case selector and be done. I am looking to improve my code so I ask, is there a better way?

0 Kudos
Message 38 of 43
(1,836 Views)

Yes, my code considers that. Works just fine (except for 4 supplies, the sign is reversed. Not sure if this is significant.)

 

Using a cluster array to iterate over all, because the sizes vary. You only need the inner code, of course.

 

differencer3.png

 

(NOTE: be careful and always show the first invalid element when sizing array containers (or show the scrollbar). Your first array actually had 4 elements. container size != array size!)

0 Kudos
Message 39 of 43
(1,832 Views)
0 Kudos
Message 40 of 43
(1,828 Views)