How do I eliminate "magic numbers" fom my VIs? 
Author Message
 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


Mon, 18 Oct 2004 07:51:14 GMT  
 How do I eliminate "magic numbers" fom my VIs?
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..



Mon, 18 Oct 2004 12:05:37 GMT  
 How do I eliminate "magic numbers" fom my VIs?
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


Tue, 19 Oct 2004 00:29:55 GMT  
 How do I eliminate "magic numbers" fom my VIs?

Quote:
> 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



Tue, 19 Oct 2004 07:31:11 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. how to eliminate selection of "username"

2. Deep Magic: "Uncommon Lisp"

3. Deep Magic: "Uncommon Lisp"

4. "Magic" asm sequences

5. Deep Magic: "Uncommon Lisp"

6. "magic lenses" in Tcl

7. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

8. BEGIN{want[]={"s1o", "s2o", "s2q", "s3q"}

9. Parsing ""D""?

10. "Fifth", "Forth", zai nar?

11. "running" numbers

12. (string->number "#e1.43#")

 

 
Powered by phpBB® Forum Software