07-09-2020 01:29 PM - edited 07-09-2020 01:31 PM
I want to alter the value inside a variant. I flatten to XML, manipulate the XML string, then Unflatten from XML.
In the attached code, the starting variant contains an enum whose value is 'OPEN AIR VALVE 1'. I want to change that to 'OPEN AIR VALVE 3', but it doesn't work, the value stays as 'OPEN AIR VALVE 1'. What's wrong?
Solved! Go to Solution.
07-09-2020 02:20 PM - edited 07-09-2020 02:21 PM
I figured it out. For an enum, the value has to be a decimal string, not a string defined in the enum.
07-09-2020 04:28 PM
You may have figured out the issue in this specific case, but you DO know that's a really weird way to change the value of a Variant, right?
I am having a lot of difficulty imagining a use case for this that could justify this particular workaround.
07-09-2020 05:33 PM
@Kyle97330 wrote:
You may have figured out the issue in this specific case, but you DO know that's a really weird way to change the value of a Variant, right?
I am having a lot of difficulty imagining a use case for this that could justify this particular workaround.
Ok, tell me a better way to do it.
07-09-2020 06:51 PM
I mean, it's one value, not one value in a giant cluster or anything packed in ... so just get a new copy of the enum as a constant and change that to a variant...
07-09-2020 08:38 PM
I have a reference to an arbitrary control (known not to be an array nor a cluster). This gives me access to the value as a variant.
I want to change the value of that control.
I receive the value in the form of a string representation of the value (e.g. if it's a boolean, I get "True" or "False"; if it's a numeric, I get numeric text such as "1.23"; if it's an enum, I get one of the enum strings).
The only way I can think of to do this is by manipulating XML.
Note: You didn't need the "To Variant" function in your example.
07-10-2020 02:47 AM
The Variant Type pallette would usually be the first place to look when dealing with variants. If that is insufficient, there is the OpenG Variant Tools add-on that is slower but more capable and complete. Both these should be better than trying to work with XML flattening.
07-10-2020 08:22 AM
@drjdpowell wrote:
The Variant Type pallette would usually be the first place to look when dealing with variants. If that is insufficient, there is the OpenG Variant Tools add-on that is slower but more capable and complete. Both these should be better than trying to work with XML flattening.
The Variant palette (and the Data Type Parsing palette) have nothing that will do what need.
The only OpenG toolkit I could find pertaining to variants is the Variant Configuration File Library package which only contains tools for writing and reading variant data to and from INI files (not what I'm doing).
07-10-2020 08:47 AM
It's called the OpenG LabVIEW Data library, I think (I am not at a computer right now or I'd check).
I wrote JSONtext using the inbuilt Variant functions, and that can handle enums, so I think it should have what you need.
07-10-2020 11:09 AM
Yes, it's OpenG LabVIEW Data Library, and I think you want this function: