LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect an empty Variant?

Solved!
Go to solution

Also remember that an empty variant can still have variant attributes that can differ.

Message 11 of 16
(1,645 Views)

@GerdW wrote:

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?

 


The only instance I could see of this method not working is if your incoming variant is "empty", but has variant attributes.

 

In that case you'd probably need to use "Get Type Information" to tell if the variant itself is empty.

BowenM_0-1620835105290.png

 

 

0 Kudos
Message 12 of 16
(1,641 Views)
Solution
Accepted by NI_Community_Support

@PNB wrote:

Is there a universal method to detect empty variants...?


Yes, the Empty String/Path? Function on the Comparison Functions Palette "is also designed to work with variants, pictures, and DSC tags." -- https://www.ni.com/docs/en-US/bundle/labview/page/glang/empty_string_path.html

 

To make this easier to find Kudo the idea to put it on the Variant Palette -- https://forums.ni.com/t5/LabVIEW-Idea-Exchange/Empty-Variant-Function-To-Variant-Palette/idi-p/42818...

Message 13 of 16
(1,404 Views)

@d.w.b wrote:

@PNB wrote:

Is there a universal method to detect empty variants...?


Yes, the Empty String/Path? Function on the Comparison Functions Palette "is also designed to work with variants, pictures, and DSC tags." -- https://www.ni.com/docs/en-US/bundle/labview/page/glang/empty_string_path.html


Nice, didn't know that. It's tricky though:

 

wiebeCARYA_0-1675675640791.png

 

So Empty String/Path is false if the empty string/Path is converted to a variant first... 

0 Kudos
Message 14 of 16
(1,314 Views)

wiebe@CARYA wrote:


Nice, didn't know that. It's tricky though:

 

So Empty String/Path is false if the empty string/Path is converted to a variant first... 


That seems logical to me.  The variant isn't empty, it contains a string.  That string just happens to be a null, but the variant does contain that null.  But I could see the confusion if people aren't aware that it works this way.

0 Kudos
Message 15 of 16
(1,266 Views)

@Hooovahh wrote:

wiebe@CARYA wrote:


Nice, didn't know that. It's tricky though:

 

So Empty String/Path is false if the empty string/Path is converted to a variant first... 


That seems logical to me.  The variant isn't empty, it contains a string.  That string just happens to be a null, but the variant does contain that null.  But I could see the confusion if people aren't aware that it works this way.


I think it's something I'll double check every time I'm going to use it. Maybe someday I'll remember.

 

But, a lot better then getting the type and checking if it's null.

0 Kudos
Message 16 of 16
(1,229 Views)