LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
tst

Add sparse enums to LabVIEW

Status: Declined

National Instruments will not be implementing this idea in LabVIEW 20xx. It is currently the feature backlog for LabVIEW NXG.

Today, the enum data type in LabVIEW only allows having sequential numeric values (0, 1, 2, 3, etc.).

 

It would be very useful to have sparse enums, meaning enums which can have custom numeric values assigned to their strings, just like you can do today with rings.

 

If you want an example where this will be useful, think of error codes - this would allow you to use an enum on the diagram to select the error, or in a case structure.


___________________
Try to take over the world!
28 Comments
tst
Knight of NI Knight of NI
Knight of NI
And, while we're at it, it would be useful if these enums could also have negative values.

___________________
Try to take over the world!
JackDunaway
Trusted Enthusiast
Even though this is a duplicate post (http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Enum-Datatypes/idi-p/925056#A468), KUDOS because I would like to see this feature.
Ray.R
Knight of NI
I like your example with error codes.  Such a feature would be awesome.  Kudos.
waldemar.hersacher
Active Participant
In my opinion an enum does not only display "Red", Green", "Blue" it is "Red", Green", "Blue". This is even reflected in the "Format into String" function. Connecting an enum will give "%s" as format specifier and not "%d".  If I need to associate number with strings I use a ring.
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
hfettig
Member

The problems with Rings is that they don't work well with type defs.

If you have a list of error codes in a typedef Ring and you add one extra number into that Ring typedef none of you already existing instances of this typedef are updated.

This is because the string is not a part of the datatype in a Ring. If you make it a strict typedef your controls and indicators get updated, but not your constants.

Therefore a sparse enum, preferable with the ability to use signed integers as well would be very useful.

tfritz
Member

Maybe it would be good to add this as another datatype. Something like "Define" datatype. I'd also like the possibility to have multiple names for one value, something that I sometimes need in my programs and that is easy in C by doing either

 

typedef enum
{
    FOO = 0,
    BAR = 0,
    FOOBAR = 10
} foobar;

 

or 

 

#define FOO       0

#define BAR        0

#define FOOBAR 10

chrisger
Active Participant

A LabVIEW equivalent for

 

#define FOO       0

#define BAR        "hello kitty"

#define FOOBAR <whatever>

 

would be great. I can imagine something like this:

 

- In the project tree there's a new menu item New->Definition. When the user selects this, a new definition is created. The user can rename the definition

- A definition is just like a Global Variable (i.e. a front panel to define the datatype and the value of the definition), but it is read-only

- the user can add the definition to block diagrams e.g. by drag'n'drop from the project tree. On the block diagram a definition is read only

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
tst
Knight of NI Knight of NI
Knight of NI

Chris, this is basically the same as the CONST idea I posted here (whether we call it CONST or #define is irrelevant, since the differences don't apply to LV).


___________________
Try to take over the world!
tst
Knight of NI Knight of NI
Knight of NI
Also, if you want NI to implement these, you should click the big "kudos" star next to the suggestion, because that's part of the mechanism NI uses to prioritize these suggestions.

___________________
Try to take over the world!
Patrick_P.
NI Employee (retired)

I actually ran into this problem today where I wanted to represent an enum from some C code in LV.  Of course the enum in C has something like the following:

 

enum {

read = 1 << 0

blue = 1 << 1

yellow =  1 << 2

... etc

}

 

It would be really nice to be able to represent this as an enum type in LV.  As someone already mentioned you could do this with a text ring but then none of the constants update anywhere on the diagram.  Kudos!

Pat P.
Software Engineer
National Instruments