03-09-2021 02:59 AM - edited 03-09-2021 03:16 AM
配列をクラスタに変換する際、
クラスターの要素数をプログラム的に設定する方法はありますか?
When converting an array to a cluster
Is there a way to programmatically set the number of elements in the cluster?
Solved! Go to Solution.
03-09-2021 03:15 AM
03-09-2021 03:23 AM
Thank you very much for your quick reply.
I’m grateful for your guidance.
Best regards,
Y.Yamazaki
03-09-2021 03:36 AM - edited 03-09-2021 03:37 AM
Hi Y,
some background:
LabVIEW is a strictly typed language: you define the datatype of any value (aka wire) at edit time.
When converting an array to a cluster you define the cluster datatype at edit time by setting its number of elements. You cannot change this setting at runtime because this would require a recompile due to the changed datatype!
03-09-2021 03:57 AM
Dear GerdW
Thank you for the detailed explanation.
I learned a lot.
Thanks again for your support!
Best regards,
Y.Ymazaki
03-09-2021 04:49 AM - edited 03-09-2021 04:50 AM
You might try a map.
For example with a string and a variant. To get variant values by name.
Or for instance with a number and an integer. That gives you integers by index. If the indices are sequential, an array will be even faster (but more work to maintain).
03-09-2021 04:20 PM
For what it's worth, I once had a decent use case for something *mostly* similar and came up with a pretty simple working solution.
It will NOT adjust the cluster size at execution time, but it *does* make the auto-sizing more automatic at development time.
I had a project where I had several different typedef'ed clusters containing different #'s of booleans. There was some generic processing and evaluation I needed to do which pushed me toward an array-based solution where I converted from cluster to array before calling the processing sub-vi. Then I'd convert back to cluster with the appropriate # of elements.
As development progressed, I would occasionally need to add or remove booleans from some of these typedef'ed clusters. And then I'd need to edit any of the places where I was converting from array to cluster to update the # of elements again.
What I found to work out nicely was to instead use the Type Cast function to convert array to cluster. I brought over a wire from my original cluster (prior to converting to array and calling the processing function) as the "Type" input. Because of the way both arrays and clusters are stored with a leading 4 byte size, this Type Cast worked just right. And whenever I changed one of the cluster typedefs to have more or less booleans, I didn't need to update the processing code. The cluster size coming out of Type Cast was automatically updated to become correct.
-Kevin P
03-09-2021 04:33 PM
Somebody made a VIM for all 256 cases at this link
VIMs attached, but reference original link/author in your program
mcduff
03-10-2021 02:38 AM
I usually convert an array of variants to a cluster by flattening the variants to string, concatenating the strings, and then unflatten to the cluster. That works for any number of elements.
03-10-2021 03:11 AM
Dear Kevin P
Thank you for your reply.
For me, the proposal may be of a high level.😅
However, we would like to thank you for your polite explanation.
We will consider it as a reference.
Best regards,
Y.Yamazaki