LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Should This Generate an Error (Variant to Data)

Solved!
Go to solution

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.

 

Example_VI_BD.png

 

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

0 Kudos
Message 1 of 5
(3,019 Views)

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.

Matt J | National Instruments | CLA
0 Kudos
Message 2 of 5
(2,987 Views)

I had a similar issue, when converting a Cluster to variant and back, it failed in much the same way.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 5
(2,959 Views)
Solution
Accepted by Hooovahh

 

Example_VI_BD.png

 

 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.

Message 4 of 5
(2,906 Views)

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.

Message 5 of 5
(2,896 Views)