07-16-2021 08:21 AM - edited 07-16-2021 08:35 AM
Does anyone know how I could create an array of keys (as a variant) and an array of values (as variants) from a map variant.
I would imagine it is possible to do this by parsing the out of variant to flattened string but I currently cannot make sense of the help file for this.
Thanks in advance
edit: after re-reading I have decided that I haven't been entire clear. I am after:
Input Magic code Outputs
Map as a variant -------> Array of variants of keys
Array of variants of values
Solved! Go to Solution.
07-16-2021 11:07 AM
So are you looking for code that takes an arbitrary map and outputs all of the keys and all of the values for that map?
07-16-2021 11:24 AM
I'll assume that's what you want 😉
Here's some code. The trick is to use a malleable VI (.vim) for the arbitrary map input, not a variant.
07-16-2021 01:21 PM
In my implementation the maps datatype is unkown (It is already a variant) so your implementation isn't quite what I am after.
After a day of banging my head against a wall I have worked out a way of doing it though
I am open to better ideas as this is incomplete and won't handle all data types atm.
07-16-2021 01:44 PM
Ahh, I think I get it- your map is already converted to a variant. That's unfortunate.
Maybe then could you make a VI that does a "variant data type" to "constant of that datatype"? You'd just have a big case structure with a constant of each type of data you need. Then you could actually convert your map variant into the real map, then use something like my method to get the keys and values.
I don't know how that'd work with clusters or arrays though.
07-16-2021 02:04 PM
07-16-2021 02:06 PM - edited 07-16-2021 02:08 PM
Somehow it feels like "NI_Data Type.lvlib:Get Map Collection Information.vi" could help, but for some reason (because it's Friday evening) it didn't.
Note that the flattened data of a map is exactly the same as the flattened data of an array of clusters with the same types. Variant To Data doesn't accept it though.
07-16-2021 02:08 PM
That is what I started out with as well, I found it got more complex when you start to handle strings, paths and arrays where there size is prepended before the data in the flattened string.
07-16-2021 02:11 PM
wiebe@CARYA wrote:
Somehow it feels like "NI_Data Type.lvlib:Get Map Collection Information.vi" could help, but for some reason (because it's Friday evening) it didn't.
Note that the flattened data of a map is exactly the same as the flattened data of an array of clusters with the same types. Variant To Data doesn't accept it though.
Yeah, i got excited by Get Map Collection Information as well. I had actually built the rest of my code knowing that was there and assuming it would do what I want. Only found out at the last minute that it didn't.
07-16-2021 02:19 PM - edited 07-16-2021 02:43 PM
@Worle wrote:
That is what I started out with as well, I found it got more complex when you start to handle strings, paths and arrays where there size is prepended before the data in the flattened string.
It still works?! (Seems pretty solid to me?)
EDIT: Even map values: