From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
X.

Replace Enum constant by String constant

Status: Declined

Any idea that has received less than 2 kudos within 2 years after posting will be automatically declined.

When deciding to replace several occurences of an enum constant by the corresponding strings in a diagram (say, in a state machine), there currently is no simple way.

From a logical point of view, it should be possible to select the enum constant, right-click and choose Replace >> String constant and get a string constant displaying the selected denomination of the enum constant. Unfortunately, currently, one only gets an empty string:

 

Screen Shot 2015-07-21 at 14.48.33.png

 

results in:

 

Screen Shot 2015-07-21 at 14.48.51.png

 

The shame is that if you had this enum connected to a Case Structure for instance, the item names are preserved:

 

Screen Shot 2015-07-21 at 14.50.07.png

 

while I would have liked to get:

 

Screen Shot 2015-07-21 at 14.55.21.png

 

my suggestion (part 1): Allow replacing an enum constant by a string constant containing its item name.

 

A natural extension of this suggestion would be, in case this enum is a typedef, to be able to perform a similar action in the Search Results window, where, after finding all copies of the typedef constants, the Replace All button would perform the action above on each individual copy:

 

Screen Shot 2015-07-21 at 15.01.51.png

 

Suggestion Part 2: Allow selecting all copies of a typedef refnum constant within a diagram and replace them with string constants containing their item names.

 

10 Comments
tst
Knight of NI Knight of NI
Knight of NI

While I understand the logic behind the idea and it's not bad in itself, I would argue that this is probably a corner case, because how common is it to replace an enum with a string? As such, I would argue that it's probably not worth the dev time.

 

Of course, you should be able to do this yourself relatively easily using scripting (which to some extent negates my position about dev time, but there's a difference between your dev time and NI's dev time). You should presumably also be able to handle the second half, at least within one VI, but I expect you could even find the typedef's callers and do it on all instances in memory.


___________________
Try to take over the world!
crossrulz
Knight of NI

To me, it sounds like you are deciding to change your architecture late in the project from using enums to using strings.  For that reason, I would prefer NI not develop this.  As Tst stated, this looks like a good spot for somebody in the commuity to make a Quick Drop plugin.


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
X.
Trusted Enthusiast
Trusted Enthusiast

I think you guys are missing the point.

I illustrated the usefulness of this feature with an example case. I never use strings for state machines, so this replacement never is my concern.

I was actually playing around with error messages, trying out enums and then realizing that I would be better off with strings (knowing full well that a Format into String would be the perfect solution for my problem, without a need to a point by point replacement of all enums constants by strings).

 

Anyway, since you have my attention, I think I want to double-down and suggest:

 

Sugestion Part 3: Provide a way to Replace every occurence of a text Ring constant by its corresponding string.

 

I hope you will now better understand what I am suggesting is missing in the Replacement Department.

tst
Knight of NI Knight of NI
Knight of NI

I understand what you're suggesting. I'm just not sure how common of a use case it is. I think I only needed this relatively rarely (I'm not saying "never", but that might be the case. I don't remember for sure).

 

To be annoying, I could say "Why not extend this to any data type - if you replace a constant with a string, give the string the value that the constant would generate if you wired it into Format Into String?". So if you have a boolean true constant, it will be replace with a string saying "TRUE". Some people might look at this suggestion and say "You know what, yes. Why not?". Others might say "That's completely ridiculous". Others might say "No, this replacement should only apply to things which already have a string component".

 


___________________
Try to take over the world!
X.
Trusted Enthusiast
Trusted Enthusiast

 


 

Great minds meet.

That's exactly what I was thinking after posting my previous comment.

Indeed that would be a natural extension.

 

And to push things even further, we should be able to "Replace" any constant of any type with a constant of any type, the default result being... the default value of that type.

So when replacing a string by a Double, the editor would try to interpret the string as a Double using the basic rules used for the equivalent function in the palette, etc.

 

Dragis
Active Participant

I don't have a strong opinion on this overall suggestion yet, still need to think about it, but in general I would like to bring up the importance of context on the diagram with any of these objects. 

 

In many cases discussed here, I would prefer the original constant remain on the diagram and have code that converts that value into the other desired type. This makes it very clear where the "calculated" value came from and leaves room for documenting why the value was converted. Let the compiler do the work of propagating the constants through the conversion code.

 

This becomes very important in some cases because the conversion may not be a directly supported conversion. For instance, if the string constant was "sin(pi/2)" you would probaly want the value of the numeric to be 1 and not the default of 0.

X.
Trusted Enthusiast
Trusted Enthusiast

@Dragis. wrote:

This becomes very important in some cases because the conversion may not be a directly supported conversion. For instance, if the string constant was "sin(pi/2)" you would probaly want the value of the numeric to be 1 and not the default of 0.

 


That's being more royalist than the king...

A case like this should certainly fall into the Default value case. At best, I'll take 2 as a second best guess. But 1? I am not even dreaming of the string "pi" being replaced by the constant pi. That sounds like a Pandora box (a whole math interpreter for a conversion tool?).

Remember that numerics are just one of the many possible destination types...

Dragis
Active Participant

X. wrote: A case like this should certainly fall into the Default value case.

That may be sufficient, but the main point I wanted to make was that even with the simple enum to string conversion it is ambiguous whether you wanted the string to take the name of the enum value ("State 1") or the actual value itself (1). Having the code on the diagram would make that unambiguous and be self-documenting as to where the value was derived.

X.
Trusted Enthusiast
Trusted Enthusiast

All right, but then that would not qualify as a "replacement" (if the original constant remained on the diagram).

In my mind, there is no ambiguity as to what I want to do when I ask to replace an enum by a string.

In other word, I don't see these "enhanced" replacements as transitive.

 

A: enum constant -> string constant = string containing the item name displayed in the enum constant

 

B: enum constant -> number constant = numeric value of the enum "digital display"

 

C: number constant - > string constant = string containing the numeric value

 

hence : A != B + C

Darren
Proven Zealot
Status changed to: Declined

Any idea that has received less than 2 kudos within 2 years after posting will be automatically declined.