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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect an empty Variant?

Solved!
Go to solution

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?

 

 

0 Kudos
Message 1 of 16
(9,044 Views)

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.

 

 

Message 2 of 16
(9,040 Views)

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?

0 Kudos
Message 3 of 16
(4,923 Views)

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…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 16
(4,917 Views)

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:

 

PNB_0-1620810246368.png

 

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.

 

 

0 Kudos
Message 5 of 16
(4,912 Views)

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?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 16
(4,896 Views)

@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:

 

PNB_0-1620810246368.png

 

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.

0 Kudos
Message 7 of 16
(4,890 Views)

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.

0 Kudos
Message 8 of 16
(4,882 Views)

@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.

 

0 Kudos
Message 9 of 16
(4,857 Views)

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"?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 16
(4,834 Views)