From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
10-22-2010 08:38 PM
I am getting an error when my application passes an empty variant (as determined by the Probe) to a Variant to Data function. The Variant is coming from a Global Variable which has not yet been initialized. I need to avoid calling the Variant to Data function as long as the Variant is empty.
How do I detect that a Variant is empty? I can not seem to find a function or constant that will help me do this.
LabView 2010 is fairly inconsistent about how empty variables of different types are detected. How come there are not empty detection methods for every data type? Why aren't they consistently done in the same manner?
Solved! Go to Solution.
10-22-2010 09:08 PM - edited 10-22-2010 09:09 PM
You can right click on one of the variant connectors on a variant function and select create constant. That will create a small empty purple box. Then you can compare your variant that and if empty, the comparison will be true.
05-12-2021 03:33 AM
Hello, unfortunately this method does not always work. It depends on the actual data type behind the variant. If the variant e.g. contains 64byte integer values, this comparison will also result in true, although data are contained within the variant.
Is there a universal method to detect empty variants also in this case?
05-12-2021 03:50 AM - edited 05-12-2021 03:51 AM
Hi PNB,
@PNB wrote:
If the variant e.g. contains 64byte integer values, this comparison will also result in true, although data are contained within the variant.
Can you please provide an example VI to demonstrate that observation?
And please explain which kind of data "64byte integer values" represent!
See this:
64bit integers are recognized in a variant…
05-12-2021 04:05 AM - edited 05-12-2021 04:11 AM
Hello,
in my example I resceive data from a MySQL Database as variant. One column for example contains 64byte Int. When I use the function Variant to data it also shows the content of this column, as you can see in the picture below:
However, when I apply the test as proposed by you on this first column, it will give true result, since the variant itself is represented like a empty variant.
Maybe this is different when LabView itself creates the variant.
I tried it exactly the way you proposed, but ended up with this problem. So your test will suggest, that this variant is empty, although it is not.
05-12-2021 04:15 AM
Hi PNB,
@PNB wrote:
in my example I resceive data from a MySQL Database as variant. One column for example contains 64byte Int. When I use the function Variant to data it also shows the content of this column, as you can see in the picture below:
However, when I apply the test as proposed by you on this first column, it will give true result, since the variant itself is represented like a empty variant.
I still don't know what a "64byte Int" should be…
Can you attach a VI containing that array of variants with the data in your image set as default value?
Can you show how you tested for empty variants?
05-12-2021 04:33 AM - edited 05-12-2021 04:34 AM
@PNB wrote:
Hello,
in my example I resceive data from a MySQL Database as variant. One column for example contains 64byte Int. When I use the function Variant to data it also shows the content of this column, as you can see in the picture below:
However, when I apply the test as proposed by you on this first column, it will give true result, since the variant itself is represented like a empty variant.
Maybe this is different when LabView itself creates the variant.
I tried it exactly the way you proposed, but ended up with this problem. So your test will suggest, that this variant is empty, although it is not.
That's not an empty variant.
The U64 is a reference to an object. It's just that the object can't be converted to anything LabVIEW knows about.
A empty .NET object is still not an empty variant.
You probably have to convert the variant to a .NET object, and then check the .NET type of that object.
Note that those object probably needs to be closed, or you'll leak memory.
05-12-2021 04:48 AM
Sorry, the problem seems to be on my side, now with your questions I tried the same approach again, and somehow also for the first column I now get "false" result when comparing with empty variant.
Sorry again for the confusion, apperently in my first attempts I must have done something else wrong.
05-12-2021 06:41 AM
@PNB wrote:
Sorry, the problem seems to be on my side, now with your questions I tried the same approach again, and somehow also for the first column I now get "false" result when comparing with empty variant.
Sorry again for the confusion, apperently in my first attempts I must have done something else wrong.
If you're querying an Excel spreadsheet, then that happens.
Excel uses the data in the first row to determine the data type, even if you tell it what the data type should be. Very annoying..
If the first row's data is empty, the rows that follow return invalid objects.
The exact details elude me, but it's messy.
05-12-2021 09:53 AM - edited 05-12-2021 09:53 AM
Isn't the function returning the error already detecting the issue? Maybe you can just handle the error? You know, "If I get an error trying to convert a variant to data, then don't do whatever"?