05-16-2024 09:13 AM
Hello all,
I want to use the same subVi for different projects. The subVi takes data from an array of clusters. Sometimes the cluster contains 2 numbers and one text string sometimes the cluster contains 3 or 4 numbers and a 2 text strings etc.
I did make a testproject. It seems I am able to use the same code to copy clusters of different sizes. So far so good. If I use property nodes I can loop trough the cluster elements. However I am not able to loop trough an array take one cluster, starting at the first row and ending at the latest. And then loop trough the cluster, like a for loop in a for loop. When using property nodes I am not able to loopt trough the array. When I try to copy a cluster I get the data from the latest row I did edit. I can use "IndexVals", this seems to add an offset to the last row I did select e.g if I did change data in row 2 and make the "IndexVals" 1 will get data from row 3. It should be easy right? Could some please tell me how to solve this? I Think I have been missing the point for the last hours.
I did ad a screenshot and a zip with the testcode. Hope someone can help me out. Thanx!
05-16-2024 09:59 AM
Hi,
I hope this would help you.
05-16-2024 10:26 AM - edited 05-16-2024 10:27 AM
You must set the indices before you read the value, a Property node always goes through the properties from top to bottom.
I did some change and suggestions to your VI.
I see Pingu did much of the same changes. 🙂
05-16-2024 10:44 AM
@~Its_Me~ wrote:
Hello all,
I want to use the same subVi for different projects. The subVi takes data from an array of clusters. Sometimes the cluster contains 2 numbers and one text string sometimes the cluster contains 3 or 4 numbers and a 2 text strings etc.
Since you seem have a limited number of well defined possible clusters, you could just turn it into a malleable VI.
(What are the possibilities? 2, 3 or 4 numeric and 1 or 2 text strings? Can there be any other differences, such as in the datatype?)
05-16-2024 11:27 AM - edited 05-16-2024 11:48 AM
@altenbach wrote:
, you could just turn it into a malleable VI.
(What are the possibilities? 2, 3 or 4 numeric and 1 or 2 text strings? Can there be any other differences, such as in the datatype?)
Here's a quick draft. It will accept arrays of A or B and return empty array otherwise. All you need is a specialization case for each valid cluster typedef.
05-16-2024 11:56 AM - edited 05-16-2024 11:57 AM
You don't need a malleable VI for this, and it can be general. (You should do error checking for unhandled cluster types)
Make a subVI whose input is a Variant. @PinguX already did most of the work. Attach your array to the subVI.
Use it with either of your arrays like below
05-16-2024 02:49 PM - edited 05-16-2024 02:53 PM
@mcduff wrote:
You don't need a malleable VI for this, and it can be general.
(Note that the OP posted in LabVIEW 2018, so your 2021 snipped might not be useful)
Except that the malleable subVI designed to handle a few well defined typedef clusters is much higher performance, because the adaptation of the inlined vim is done at compile time.
While your subVI is more general, it juggles a lot of data into different data structures and does several type detections at runtime. This is significantly more expensive.
For a general solution, we should probably switch to OOP here instead.
05-16-2024 04:35 PM
@altenbach wrote:While your subVI is more general, it juggles a lot of data into different data structures and does several type detections at runtime. This is significantly more expensive.
True. But how many elements is the OP processing to warrant the performance increase over the generality? If the cluster changes names, then the malleable VI needs to be updated. Which costs more, programmer time or CPU time?
@altenbach wrote:For a general solution, we should probably switch to OOP here instead.
Variant parsing, in my opinion, is an extremely useful and somewhat overlooked part of LabVIEW. Not sure if it always needs to be in an object though.
05-21-2024 09:32 AM
Thank you guys, your answer is more than I had hoped for! I get 2 times a valid answer for asking 1 question.
Some background
The function will be used to safe a array of settings. The array will never be extremely large if there are 40 rows then its a lot for these tests. When the test runs the test will run for a few hours. There are however 3 testmachines and in the future there will be more. Every testmachine is using a different cluster width. There will also be some other code in the subvi. The main reason for my question was I did not want to change the subvi 3 times. At this time I will use the solution from pinguX.
To be honest I did never hear of the malleable VI. Now I do and I can see some situation where I can use it! As you guys describe it depends on the situation which one to choose.
There is one other question that pups up, do I need to use a close reference in the subvi? like this:
Thank you all for the help!
05-21-2024 10:38 AM
@~Its_Me~ wrote:
There is one other question that pups up, do I need to use a close reference in the subvi? like this:
Thank you all for the help!
I do not believe it needs to be closed; but closing it will not harm anything.
I suggest you use @pinguX's solution with the modification I suggested. Make a Variant input to the subVI, then you have no references, no boolean, and in the future it will automatically adapt to any new cluster.