From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unflatten from XML not working

Solved!
Go to solution

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?

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 1 of 11
(2,208 Views)
Solution
Accepted by topic author paul_cardinale

I figured it out.  For an enum, the value has to be a decimal string, not a string defined in the enum.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 2 of 11
(2,186 Views)

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.

0 Kudos
Message 3 of 11
(2,156 Views)

@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.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 11
(2,142 Views)

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...

 

Kyle97330_0-1594338655234.png

 

 

0 Kudos
Message 5 of 11
(2,136 Views)

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.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 6 of 11
(2,118 Views)

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.

0 Kudos
Message 7 of 11
(2,086 Views)

@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).

 

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 8 of 11
(2,064 Views)

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.

0 Kudos
Message 9 of 11
(2,057 Views)

Yes, it's OpenG LabVIEW Data Library, and I think you want this function:

Set Enum String Value.png

0 Kudos
Message 10 of 11
(2,038 Views)