Jump to content

Get Variant Attribute... what's the trick ?


Recommended Posts

Dear all,


I'm beginner with variant, and spending few hours to bump on a simple question :frusty:, I prefer asking to more experienced people...


So I just don't manage to get the attributes from a variant. Even an this simple example, names and values stay empty...

Thanks for your help,




Link to comment

Attached is a quick example.  Basically you set the values as a look up table where a string corresponds to a value.  Then you can get that data back by providing the string and performing a read.  This is apparently a very efficient method of getting data.  You'll need to convert the variant read back into something useful and for that you need to know the data type that it was written in.  Here you may run into errors.  Like in my example if I tried to read all attributes and said that the data type was string, one would read fine, the other 2 reads would generate an error because the data type isn't the same as it was written with.


EDIT just saw you use 2010 so here is the same VI in 2010.

Variant Attribute Example.vi

Variant Attribute Example 2010.vi

  • Like 1
Link to comment



I think you mistake the attributes of a variant for the elements of a cluster. These are two completely different things.


As hooovahh pointed out above, you set (or define) the attributes yourself. So you first have to define an attribute, before reading the attribute names and values makes any sense.



I believe you are looking for a way to inspect a variant and - if it is a cluster - access its elements. This is most easily done by using the appropriate OpenG functions.



Regards, S.

Link to comment
Basically the "trick" is that Variant data type has two completely unrelated uses:
  1. It can be used as a "wrapper" for any other data type
  2. It can function as a "hash table"

And it can be just one (x)or the other, not both at the same time.

This is not true.  You can have a variant that has data in it being your "wrapper", and then that variant can have attributes your "hash table".  You can then read the attributes, and you can convert the variant back into the data type it was before.  The two uses aren't completely unrelated.  Say I have a waveform.  That can be XY data, or X0, delta X, Y so maybe I choose to put it into a variant so it can be either.  Then I want to keep information like scale, or plot names I could store those as attributes so my single wire has all that information.  Sure in this case maybe a cluster would be a better option but it is one way a variant can hold everything you need.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.