LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Change value of variant directly?

Solved!
Go to solution

Suppose I have a variant from an external source.

Further suppose I know the data type, but I do NOT know the attributes and their values (if any).

 

Is it possible to directly change the value of the variant, "under the hood" so to speak, and leave all the attributes intact?

 

I realize I can read all the attributes, generate a new variant with my new data and write them all back, but that seems highly inefficient.

Casting new data to a variant, then using Variant to Data to convert that to the Original variants type seems to work as well. Again, kludgy.

 

Poking around with "..vi.lib\Utility\VariantDataType\*.* but so far not finding a 'direct' method.

 

Thanks!

0 Kudos
Message 1 of 8
(3,832 Views)
Solution
Accepted by FTI_Newton

You can use the inplace element structure to set the value of an existing variant.  It will preserve any existing attributes.

Message 2 of 8
(3,788 Views)

@CMal wrote:

You can use the inplace element structure to set the value of an existing variant.  It will preserve any existing attributes.


That's good information to know.  I know I'll run into that situation one of these days.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 8
(3,780 Views)

Brilliant!

Didnt' occur to me to check if in-place would take a variant. Seems obvious now. Thanks! :manvery-happy: 

0 Kudos
Message 4 of 8
(3,760 Views)

Then you should mark C-mal's post as the solution to your question rather than your own thank you message.  You will need to go to the options menu to the upper right of your message to unmark it as the solution.

0 Kudos
Message 5 of 8
(3,747 Views)

Oops - my bad. Thanks for the heads up. Credit where it's due, no doubt.

0 Kudos
Message 6 of 8
(3,692 Views)

Does it keep the attributes if you use an in place element structure with maps? Maybe I made a mistake, but directly replacing the new value of the variant drops the attributes, I had to go thru all the attributes of the existing value and write them to the new one. Again, could be my mistake.

 

1984_0-1667809227799.png

 

0 Kudos
Message 7 of 8
(1,735 Views)

Hi,

I think you need a second 'In Place Element Structure' with a 'Variant To / From Element border node' working on your variant.

0 Kudos
Message 8 of 8
(1,719 Views)