11-11-2023 01:56 PM
I'm curious and couldn't find an answer in LabVIEW help: Does anyone know why ".NET Object To Variant.vi" and "To .NET Object.vi" exist?
Is it bad to use "To Variant" and "Variant To Data" for .NET objects and, if so, why?
I have been using the latter two without apparent problems, as I do for all datatypes, and only discovered the former two .NET specific VIs by chance.
Thanks
Solved! Go to Solution.
11-11-2023 03:49 PM - edited 11-11-2023 03:56 PM
Hi,
These are completely different sets of functions:
"To Variant" wraps any data type into a LabVIEW Variant.
"Variant To Data" unwraps the data back to its original (strict) type.
These are used when you want to pass generic data around your application.
"To .NET Object.vi" converts simple LabVIEW types to their .NET equivalent:
- Double Float -> System.Double
- String -> System.String
- Boolean -> System.Boolean
- Time Stamp -> System.DateTime
- Path -> System.String
- .NET Refnum -> the same .NET reference
- Array of String -> System.String[]
…
Other types such as enumerations, clusters, LabVIEW-only refnum types… are not supported and will throw an error.
".NET Object To Variant.vi" does the opposite and tries to convert a simple .NET object to its LabVIEW equivalent.
These 2 functions are generally not needed since LabVIEW automatically converts properties and method parameters to their LabVIEW equivalent. You only need them in case the .NET property/method takes a generic Object as a parameter.
Regards,
Raphaël.
11-11-2023 06:54 PM - edited 11-11-2023 06:58 PM
Thanks, Raphael.
This other thread added to my confusion where people appeared to be mixing their use: https://forums.ni.com/t5/LabVIEW/net-reference-management-when-we-use-net-object-to-Variant-vi/m-p/4...