LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
jandrengen

Strict Variant To Data function

Status: Declined

Any idea that has received less than 3 kudos within 3 years after posting will be automatically declined.

When handling data in a Variant, I'm always interested in knowing the exact type of the data within the variant. In my own code I could add an attribute with the information, but when getting the value of a control that is not possible.

The problem is the automatic conversion done by the Variant To Data function. If the data is a double and the type parameter is set to an integer type, the double value is converted without any error.

 

My suggestion is to add a boolean parameter to the Variant To Data function to force it to return an error if the type parameter is not exactly the same as the data type.

 

Variant To Data Suggestion.png

12 Comments
jandrengen
Member

The idea came from the work on an application where the VIs pointed out by tst certainly could be the solution. I definitely will dig into the VariantDataType VIs and the VIs in OpenG.

For my application it might be easy to work around the coercion danger, but the error could be helpful during development.

 

So, I still think the suggestion is useful, as Intaris and The J expresses better than I.

 

Sorry for the bad example code.

Darren
Proven Zealot
Status changed to: Declined

Any idea that has received less than 3 kudos within 3 years after posting will be automatically declined.