Discussion:
Get variable name and type dynamically
(too old to reply)
ishieh
18 years ago
Permalink
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
smercurio_fc
18 years ago
Permalink
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.


Main VI.vi:
http://forums.ni.com/attachments/ni/170/246584/1/Main VI.vi


subVI.vi:
http://forums.ni.com/attachments/ni/170/246584/2/subVI.vi
smercurio_fc
18 years ago
Permalink
Just to follow up with the request that you wanted the VIs in 8.0...


Main VI.vi:
http://forums.ni.com/attachments/ni/170/246778/1/Main VI.vi


subVI.vi:
http://forums.ni.com/attachments/ni/170/246778/2/subVI.vi
smercurio_fc
18 years ago
Permalink
<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?
parthabe
18 years ago
Permalink
smercurio_fc wrote: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.


Hi smercurio, I dont understand your statement, it employs the use of an unsupported "scripting" function, as evidenced by the red property node.
Is it there inside the Vi I attached, or are you telling in general ?
I cant see these things in my VI. :smileyindifferent:
Please clarify me reg this. I m using LV 7.1.

Continue reading on narkive:
Loading...