LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I eliminate "magic numbers" fom my VIs?

Is there a Labview equivalent to #define in C where you can give your constants names and values that can be easily changed without having to go through all you VIs and look for the numbers?
Thanks,
David
0 Kudos
Message 1 of 4
(1,445 Views)
Yes, they are called enumerated types. Create one (as a typedef) that has all the possible values for a given input or output and you never have to worry about what a "4" means again. Alternately, you could use a ring control -- which really is a numeric with a text label.

emuns and ring controls are both available as controls, indicators or diagram constants.

Mike..

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 4
(1,445 Views)
Mike,
Is it really the same thing? From reading the documentation it is not clear that I can assign say the string "Offset" to be equivalent to 32. It seems more like a enumerated type in C where I define as series of strings "Red", "Green" and "Blue" to be equivalent to 0,1,2. In LabView it appear I am limited to setting 0 as the first value of an enum type. Is this correct? If not maybe I can use this.
I do not have more than one possible value. It is not an input, it is a hard-coded program constant, and I want it to be defined once but used many times in a variety of sub-VIs. Maybe I need to create aglobal variable?
Thanks,
David
0 Kudos
Message 3 of 4
(1,445 Views)
> Is it really the same thing? From reading the documentation it is not
> clear that I can assign say the string "Offset" to be equivalent to
> 32. It seems more like a enumerated type in C where I define as series
> of strings "Red", "Green" and "Blue" to be equivalent to 0,1,2. In
> LabView it appear I am limited to setting 0 as the first value of an
> enum type. Is this correct? If not maybe I can use this.
> I do not have more than one possible value. It is not an input, it is
> a hard-coded program constant, and I want it to be defined once but
> used many times in a variety of sub-VIs. Maybe I need to create
> aglobal variable?


The enum in LV is closest to the enum in C, pascal, etc. And you are
correct that it is the stict type that
maps sequentially from zero. It
is a good choice for ordered sets where you do not care what the value
of the objects are or look the value up elsewhere.

For the systemwide constant value, a global is one choice, and a common
one from many diagrams I've seen. A better alternative IMO is to use a
VI. Make a little icon or give the subVI a good name. Have the value
on the connector output and place the subVI in your user.lib for easy
access from the palettes. Another good thing about this is that you can
bundle a couple of these together on the connector pane or even add
simple selectors as inputs to start building up a small retrieval
interface. Don't forget to make the values be default before saving.

Greg McKaskle
0 Kudos
Message 4 of 4
(1,445 Views)