01-25-2019 02:58 PM
Each supply has 2 elements, a before and after. So there are anywhere from 2 to 8 measurements depending the number of supplies.
01-25-2019 03:02 PM
@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.
01-25-2019 03:04 PM
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
01-25-2019 03:13 PM - edited 01-25-2019 03:24 PM
01-25-2019 03:16 PM
You attached an empty VI. Can you attach the code shown in the picture instead?
01-25-2019 03:23 PM
This should be the one.
01-25-2019 03:28 PM
Try this. You get an array of supplies.
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.
01-25-2019 03:34 PM - edited 01-25-2019 03:36 PM
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?
01-25-2019 03:43 PM
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.
(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!)
01-25-2019 03:46 PM