Jump to content

#define constants in LabVIEW


Recommended Posts

There has been a recent discussion on Info-LabVIEW about how to implement constants in LabVIEW. We are talking about a constant value that is used many times in a program. These are defined at compile-time, not run-time. Several options were discussed (Globals=nasty, Simple VI with constant output=a file for each constant!, VI with cluster=have to have vi and unbundle for each call). I think a Global Variable-like VI (no block diagram) that automatically 'Set Current Values to Default' would be good. When dropped on a diagram, it would show up as an enum-like constant. It would be polymorphic. (see attachment)

post-14-1087600847.png?width=400

Link to comment

I guess there is a place for a new type of constant however I don't feel that it is really such a big issue.

Personally I prefer to use a sub-VI for placing constants. I don't understand why you need to have one VI per constant. Most of the time constants belong in groups. For example you would have DAQ settings or Instrument settings. You would then place all constants on the diagram of a subVI. Of course you would put them inside of a cluster then output that cluster to a terminal of the VI. A simple unbundle will give you what you need. If you don't like clusters and unbundle then use multiple output terminals instead. Why is this so hard?

There is also a hidden potential here that is not evident at first but I will explain. If you created a VI for each functional group of constants you could easily convert them (down the road) from static hard coded data objects into flexible variables that can be abstracted and manipulated externally, even as a built executable. Each constant VI can be edited and replaced with a read\write from ini file. This allows you to implement code

Link to comment

After reading Conway-Watts I've started putting all 'constants' in INI files. There just seemed to be a desire from some to have a 'cleaner' compile-time constant, so I made a suggestion. I can think of other things I would like to see in LabVIEW first.

Link to comment
After reading Conway-Watts I've started putting all 'constants' in INI files. There just seemed to be a desire from some to have a 'cleaner' compile-time constant, so I made a suggestion. I can think of other things I would like to see in LabVIEW first.

Yes the Conway-Watts book you refer to has some great examples of this.

As far as the value of posted suggestions\wishes, we have quite a bit of influence in the direction of future versions of LabVIEW as long as the wishes get posted to the right location:

LAVA wish list policy.

My opinion is just that, an opinion and does not indicate right or wrong. Keep those opinions and suggestions comming, they are all welcome! :thumbup:

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.