SebS Posted January 15, 2014 Report Share Posted January 15, 2014 Dear all, I'm beginner with variant, and spending few hours to bump on a simple question , 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, Seb Quote Link to comment
hooovahh Posted January 15, 2014 Report Share Posted January 15, 2014 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 1 Quote Link to comment
SDietrich Posted January 15, 2014 Report Share Posted January 15, 2014 Hi, 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. Quote Link to comment
mike5 Posted January 16, 2014 Report Share Posted January 16, 2014 Basically the "trick" is that Variant data type has two completely unrelated uses: It can be used as a "wrapper" for any other data type It can function as a "hash table" And it can be just one (x)or the other, not both at the same time. Quote Link to comment
hooovahh Posted January 16, 2014 Report Share Posted January 16, 2014 Basically the "trick" is that Variant data type has two completely unrelated uses:It can be used as a "wrapper" for any other data type 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.