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

Adding CONSTs to LabVIEW

Status: New

I would love it if LabVIEW had logical constants, similar to what other languages have. Basically, a logical constant is similar to a variable (i.e. it's a value which is assigned a name), but its value is set at compile time. CONSTs help code readability.

 

In LabVIEW, a CONST would basically be similar to a global variable, with two differences:

 

1. It would be read only (so no race conditions, everyone can relax).

2. Changing the value on the front panel of the CONST VI will automatically require the user to save the VI, without needing to manually set the new value as the default.

 

Today, you can implement these in LabVIEW using all kinds of methods, but non of them is as convenient as this.


___________________
Try to take over the world!
15 Comments
Matthew_Kelton
Active Participant
If NI does this, I would like to see it work (assuming my understanding is correct) like other text based languages where the compiler actually replaces the CONST name with the value.  In LV, that means performance-wise we don't have any performance degradation over actually using a constant.
Ray.R
Knight of NI
Great idea tst.  Glad I read the post about WORM.  If they made Globals read only or constant, that would be great.  I'm sure Ben would sleep better at night.
rgvdh@rdf
Member

If you look at the original problem statement above the use of a VI whose sole job is to output one or more constants accomplishes 90% of what is wanted.  The only new thing requested is

"2. Changing the value on the front panel of the CONST VI will automatically require the user to save the VI, without needing to manually set the new value as the default."

This could be achieved by setting the VI properties appropriately;  I don't know if it's currently possible to set a vi so that it automatically does a "make current values default' when you save it.  If that were made available, I believe tst would have everything he needs: 

Change the value of the constant. 

Run the program.  

If you liked the result, hit "save"; if you didn't, close without saving.

tst
Knight of NI Knight of NI
Knight of NI

No, a subVI won't help, because it requires a lot more work than a global variable - you need one VI for each constant (assuming you're not going to fill the connector pane with outputs), you need to create icons, you need to have additional files and documentation, etc.

 

The one thing a subVI does already make easy is what you suggested to add - if you have a subVI, you can just use a constant in its diagram and solve your issue - change the constant and the value is automatically kept.


___________________
Try to take over the world!
bienieck
Active Participant

I VOTE FOR "even stricter type definition"!!! 

Michał Bieńkowski
CLA, CTA

Someone devote his time to help solve your problem? Appreciate it and give kudos. Problem solved? Accept as a solution so that others can find it faster in the future.
Make a contribution to the development of TestStand - vote on TestStand Idea Exchange.