LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Data reliability when converting to & from a variant...

Solved!
Go to solution

It is possible to convert any data type to a variant, and then back again.  When doing so, are there any data types that will lose information during the conversion process?  If so, why?



Never say "Oops." Always say "Ah, interesting!"

0 Kudos
Message 1 of 2
(2,086 Views)
Solution
Accepted by J.Mamakos

Yes, you can convert any type to a variant and back. There is a VI called "Variant to Data" that will take a type as an input. This is sued to convert the variant back to the correct data. The receiving side of the variant must know what data type to expect. It can't derive it from the variant. However, you can use a generic data cluster that consists of an identifer and a variant. Then you can have different data types that the receiving side can process. It is a two step process. One to conver the variant to the general type (cluster of type and variant data). The second would be a case statement which uses type to then covert the inner variant to the specified type. This approach is used for generic messaging systems. The higher levels of the code will know what to do with the data. The lower levels are just passing generic data around.

 

I am not aware of any information that gets lost when converting data to and from a variant. I certainly haven't encountered any problems using them.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 2
(2,055 Views)