Jump to content

Automatically Coerce Enum to String


Recommended Posts

I tend to used type-def enum's to keep track of messaging commands, VI lists, whatever. Often I want to grab the text of the enumerated type, which is quite simple using the 'Format Into String' vi.

If I have a sub-VI that needs a String input, it would be nice to simply wire the Enum into the node, giving me an automatic coercion without forcing me to put the 'Format Into String' vi inbetween. This is possible for numeric inputs to sub-vi's. And the Enum type is a combination of string and numeric, so it shouldn't be difficult to add.

Not a big deal, but it has annoyed me recently.

David

Link to comment
Do you have the OpenG Toolkit installed? I believe there is a function that will give you a quick conversion. It's not a coercion dot, but it's pretty easy.

Right, you will need to make the input a Variant, which anything will coerce to, and then extract the string value of the variant using the Get Strings From Enum function in the lvdata (LabVIEW Data Tools) package.

Link to comment
I tend to used type-def enum's to keep track of messaging commands, VI lists, whatever. Often I want to grab the text of the enumerated type, which is quite simple using the 'Format Into String' vi.

If I have a sub-VI that needs a String input, it would be nice to simply wire the Enum into the node, giving me an automatic coercion without forcing me to put the 'Format Into String' vi inbetween. This is possible for numeric inputs to sub-vi's. And the Enum type is a combination of string and numeric, so it shouldn't be difficult to add.

Not a big deal, but it has annoyed me recently.

David

Why not give your subvi two inputs a string and an Enum. If the String is empty use the Enum and convert otherwise use the String input.

Polymorphic vis might be a solution too.

Link to comment
If you have a numeric control in a subVI and you wire an enum into it, it will be coerced. My understanding is that David wants the same to happen with a string control.

OK I read that it was possible for numeric to be converted to a string input. The world can resume its rotation now.

Link to comment

Thanks for all the feed back. Sorry I was so ambiguous with my first post. I am aware of the various work-arounds, and have used quite a few. I don't quite like having two separate inputs (string and enum) but polymorphism or a variant input are my favorites. The variant input requires me to see if the input was an enum, string, or something else. A bit of extra work.

The reason for the "wish" is that sometimes there are vi's already written that take string inputs (or vi.lib vi's for that matter). If the enum contains the number and the strings in it's type, a coercion dot is not unreasonable.

By the way, I have loved the OpenG toolkit and the Variant-Enum vi's have been very handy. Thanks for all your hard work.

David

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