Hidden Gems in vi.lib

cancel
Showing results for 
Search instead for 
Did you mean: 

A note about the VariantDataType VIs and data type checking

In the Hidden Gems in vi.lib presentation (posted here), I discuss the benefit of using the VariantDataType VIs to check variants to see if they match a specific type. The example I gave in the presentation was checking a variant to see if it's an error cluster. In the presentation I talk about how the VariantDataType approach is superior to the Variant to Data approach, since Variant to Data will attempt to convert the type even if it doesn't match exactly.

When I gave this presentation at the European CLA Summit last week, an audience member pointed out that, although Variant to Data will attempt the conversion for non-exact types, the Variant To/From elements on the In Place Element Structure can be used for this purpose:

best.png

I was not aware that Variant To/From does more strict type checking than Variant to Data. However, after investigating this claim further, I discovered that the check is not strict enough. For example, replacing the DBL with a U32 will not generate an error, and the code will erroneously declare that the type is an error cluster:

best2.png

So, for the time being anyway, it is still a best practice to use the VariantDataType VIs when checking a variant to see if it exactly matches a known type.

Message 1 of 1
(7,010 Views)