Jump to content

programmatically create variants


Recommended Posts

Hi,

i am trying to programmatically create an array of variant which should be able to contain dynamic content.

Because I want to query specific data from that variant later on I need to name every item. I tried to do it with the SetTypeInfo VI but unfortunately it overwrites the data contained in the variant. Does anyone know another solution?

I'll attach a demo which demontrates this behaviour. btw. I left out the array in this demo.

cheers Heiko

Download File:post-6437-1161269090.vi

Link to comment
i am trying to programmatically create an array of variant which should be able to contain dynamic content.

Because I want to query specific data from that variant later on I need to name every item. I tried to do it with the SetTypeInfo VI but unfortunately it overwrites the data contained in the variant. Does anyone know another solution?

First off, the SetTypeInfo VI is expecting a Type Descriptor as input, not a data variant as you are intending.

Secondly, there is a wonderful option for what you are envisioning. It is using the Attributes of a variant. You can set a variant attribute by name and then retrieve it later by name in your program. And it is quite fast for 8.0 and up. Check it out.

post-1519-1161273138.png?width=400

Link to comment
First off, the SetTypeInfo VI is expecting a Type Descriptor as input, not a data variant as you are intending.

Thanks for the reply it brought me a lot of new ideas.

I already saw that get/set attribute stuff, but was not using it because initially i wanted to automatically serialize my wires using GetTypeInfo and a case structure to format the data into a string like this "name=value". So i though it would be the most elegant way if i could just recreate that wire with its name. But it seems that there is still no way of programatically naming wires during run time. :(

Anyway this variant attribute stuff looks like it is a good hack for doing 'item' => 'value' lookups (similar to hashes in perl). :thumbup:

cheers heiko

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.