LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get variable name and type dynamically

Hi all,

What I am trying to do is be able to read the name (label) and type of a variable.  Here is a simple example of what I want to do:

1.  Main VI calls a sub VI, data is passed to the sub VI in a cluster.
2.  Cluster contains four elements: a boolean, a string, a double, and an integer.
3.  The sub VI should take this input cluster, read the name of each element, concatenate each of those into one string (tab delimited).
4.  The sub VI should also read the type of each element, and be able to use this type to decide on a format string to use when converting the element's value to a string.

I can do all of the programming above except for being able to read the type and name of any given element of the input cluster.  I know you can use a property node to get these data if you were trying to do so for a front panel control, but can you do this for a variable that has been passed into a sub VI using a cluster?  Also, my example is simple; I have about 50 different inputs I want to perform this operation on.  Thanks in advance for any help you can give to me.

-Ian
0 Kudos
Message 1 of 16
(9,694 Views)
You basically use control reference to do this sort of this, as shown in the attached sample. There may be an easier way to do what you're looking to do. When you say you want to convert it to a string, is this supposed to be a flattened string of the value, or a human-readable formatted string? If it's a flattened string you can just flatten to string the cluster control directly.
Download All
Message 2 of 16
(9,679 Views)
smercurio_fc,

Thank you for the reply, but unfortunately I am running LabVIEW 8.0.1 so I can't load your examples, is there a way you could convert it to my older version or just post a screenshot?  Also, to answer your question about the string, I want a human readable string, basically it needs to be written to a text file.  Thanks for your help.

-Ian
0 Kudos
Message 3 of 16
(9,678 Views)
Maybe you can rty something like this.
- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 4 of 16
(9,663 Views)
Unfortunately Partha, that suggestion doesn't answer the question, since that provides flattened data, and Ian wants human-readable strings. Also, it employs the use of an unsupported "scripting" function, as evidenced by the red property node.

I would suggest heading over to open.org and downloading their VI Package Manager. This will allow you to download individual OpenG libraries. The one you want is the OpenG Variant package. You may need to download others due to dependency, but the VI Package Manager will inform you of this. It's got VIs in there that will allow you to write clusters to INI-file formatted structure. No fuss, no muss. I think this may be a better solution for you.
Message 5 of 16
(9,646 Views)
Here are a couple other previous posts that may be of interest:

http://forums.ni.com/ni/board/message?board.id=170&message.id=222324&requireLogin=False

http://forums.ni.com/ni/board/message?board.id=170&message.id=241608&requireLogin=False

http://forums.ni.com/ni/board/message?board.id=170&message.id=78012&requireLogin=False
Doug M
Applications Engineer
National Instruments
For those unfamiliar with NBC's The Office, my icon is NOT a picture of me 🙂
Message 6 of 16
(9,632 Views)
Just to follow up with the request that you wanted the VIs in 8.0...
Download All
Message 7 of 16
(9,629 Views)
I appreciate everyone's help; I looked through your examples and other threads and came up with a solution that I think suits my needs best.  I've attached it in case someone else might find it useful.

-Ian
Message 8 of 16
(9,611 Views)
Something I realized I forgot to mention as a word of caution: the subVI that I used (GetTypeInfo.vi) seems to run very slowly.  For my application, I only need to read the label info once (a data file header).  I then will write the values of the variables many times (thousands of times per experiment).  However, since finding the data type of the variants is relatively slow, I only do so the first time I am reading in data from the cluster.  I can then store the data types in an array to be used on subsequent calls to this data file writing VI.  The time savings of this setup is significant.

-Ian
0 Kudos
Message 9 of 16
(9,607 Views)
<Saverio scratches his head for a while and frowns...>

You know, I can't quite figure out why you need to do this. I can see doing this kind of operation if you're trying to save configuration information for a VI front panel or something. That's something that comes up often. But if you're doing it to save data, there's better ways to do it than going through variants the way you're doing. Is the cluster the individual data item that you have, and you have an array of these? It seems to me that you can save this as a simple table. Why do you need to go through the variants just to get the value?
Is this intended to be parsed somehow? If so, I can already see a problem. The control labels are delimited by a space. What if the label has a space, as in your example with "Double Float". How do you know where one label ends and the next one begins?

Your initial question was very specific, and based on your last post it seems to me that your overall goal may require a different solution. Do you have an example of the data that you're trying to save and what format you're trying to get to?


Message 10 of 16
(9,599 Views)