LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading control label from variant

Solved!
Go to solution

 

Hello,

 

I have a variant that contains the label names and the addresses of different controls. What I would like to do is be able to read just the label names (In the screenshot, AO3 Address, AO4 Address, etc). I tried using a flatten to string but the data string contains the location of the physical address (not the label name). Is there an easy way to read just that first piece of infromation? I also tried using variant to data, but I'm not always sure what the data type is going to be. Thanks.

 

 

0 Kudos
Message 1 of 10
(5,399 Views)

Morning Newbie

 

I have had a look at this and it would be great if you could post your code up as I am still slightly unclear as to what format you varient is in.

 

If you would attach a simple example then I will take a look and hopefully we can come to a good solution.

 

best regards

Graham Green

Sr. Product Marketing Manager

National instruments
0 Kudos
Message 2 of 10
(5,387 Views)

Hi there

 

you can't convert a variant to data without knowing the exact datatype. But you can use a reference to the cluster instead of the variant data to obtain the label names, the datatypes and the values of the cluster elements. see attachment.

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
Download All
Message 3 of 10
(5,381 Views)
With respect to how to do it with the variant, OpenG's Data Tools library has a VI ("Get Cluster Element Names" ) to do this. If you look at the code for it you will see that it relies on using the Variant to Flattened Data function.
Message Edited by smercurio_fc on 10-09-2008 12:03 PM
Message 4 of 10
(5,353 Views)

 

Hi there

 

The OpenG "Get Cluster Element Names" uses the data type descriptor. The format of this descriptor has changed from 7.x to 8.x, so you should be carefull when upgrading to 8.x.

 

LV help for "Type Descriptors":

 

Note  The format in which LabVIEW stores type descriptors changed in LabVIEW 8.0. LabVIEW 7.x and earlier stores type descriptors in 16-bit flat representation. LabVIEW 8.0 and later stores type descriptors in 32-bit flat representation. The information for LabVIEW 7.x and earlier applies if you use the Convert 7.x Data mode of the Flatten To String function. The following information applies for LabVIEW 8.0 or later.......

 

Anyway: I was wrong, yes you CAN get the names from variant data without knowing the exact data type of the cluster.

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
Message 5 of 10
(5,347 Views)

Thanks for all the help and quick replies. The openG solution is exactly what I am looking for. Since I have a later version of LabVIEW (8.5), I haven't tried looking into it b/c of the caution about the type descriptor format changing.

 

Hopefully, there is another solution out there. I've included a sample program to illustrate what I am trying to do. By toggling a product selector control, I am able to update the label names on the variant data dynamically. The cluster data, however, stays static. If I could somehow read back the labels from the variant as a string, or some other way, that would be great. Thanks again!

Download All
0 Kudos
Message 6 of 10
(5,337 Views)
Well, I just tried the OpenG VI in 8.6 and it worked for your cluster. Can't tell you if it will work in all cases though.
0 Kudos
Message 7 of 10
(5,323 Views)

What happens with OpenG and LV 8, is that the code is developed in LV 6, the open and upgrade functionality of LV makes sure the behaviour stays the same, so you should not have a problem (as smercurio found out).

If you find a case where it doesn't work please report it to OpenG.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 8 of 10
(5,305 Views)
Solution
Accepted by topic author Newbie217
Thanks all! I will go with the OpenG solution. So far, so good 😃
0 Kudos
Message 9 of 10
(5,298 Views)

You could also use the flatten to XML vi and pull out the names,see attached.

I don't do any errorchecking, and I am assuming you put in a variant of a cluster.

You could easily make it more versatile.

I use a subvi to insert data into a database, now I can save any cluster into any table, since I know the columns.

I like it better than the reference to a control, as the control values may not be updated, especially in a subvi.

 

-Nils

 

 

Download All
0 Kudos
Message 10 of 10
(4,816 Views)