11-14-2016 04:21 PM - edited 11-14-2016 04:38 PM
So I ran into a case I never thought I would but I have some code that is taking an empty variant, and turning it into...an empty variant using the variant to data. To my surprise this generates error 1.
Now the actual code has the Reply Data Type, as a type def template that a developer can then replace and the other places that the type def is used gets updated. But if they choose not to update the type def then I anything would be wrong since it would be converting from one empty variant to another. Is this expected? The easy solution is to just check for an empty variant on the input, and if it is, then use a case structure with the default data of the Reply.
Edit: LabVIEW 2015 SP1 f3 32-bit, Windows 7 SP1 x64
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
Solved! Go to Solution.
11-14-2016 06:28 PM
I wouldn't have expected this to happen (I would expect it to behave as if the VTD were not there) but it's definitely a corner case and I probably would only expect to see what's in your snippet if I was scripting something and didn't want to create a special case for passing variants.
Also, somebody called me recently when one of our utilities was returning error 1 at variant to data and I couldn't think of any possible ways to actually throw that error so I am glad that I now know one reason.
11-15-2016 02:20 AM
I had a similar issue, when converting a Cluster to variant and back, it failed in much the same way.
/Y
11-15-2016 03:13 PM
Is this expected?
Yes (though confusing). The Variant to Data node converts the contents of the Variant into the type you specify. The input Variant contains nothing (type=Void), and can't be converted to anything. If it instead contained another Variant, then the above code would pull out that inner Variant.
11-15-2016 03:33 PM
You know I think that might have been the case I was coming up against. For the longest time I swear this code just worked fine, but I'm guessing it was because it was turning a variant that was non void, but contained a variant, that was void, and it was able to turn it into a variant. Moving forward I have a check to say if the input is a variant void, and if it is then to just pass through the default data for the type on the input.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord