LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why use the .NET Object to Variant and To .NET Object VIs?

Solved!
Go to solution

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

0 Kudos
Message 1 of 3
(1,361 Views)
Solution
Accepted by topic author banksey255

Hi,

 

These are completely different sets of functions:

 

raphschru_0-1699739252801.png

 

 

"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.

Message 2 of 3
(1,344 Views)

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...

0 Kudos
Message 3 of 3
(1,319 Views)