Jump to content
Sign in to follow this  
Eugen Graf

Global constants

Recommended Posts

Hello, how can I create a global constant. Should I take a global variable? Or can I do it with typedefs?

Eugen

Share this post


Link to post
Share on other sites

There is no such thing as a Global constant. Globals exist in only one form. They are nodes that are placed on the diagram. In the Functions palette>Programming>Structures>Global Variable. After placed, double-click on the black node to open the Global front panel to place your data type controls.

Share this post


Link to post
Share on other sites

QUOTE(Eugen Graf @ May 11 2007, 10:17 AM)

Hello, how can I create a global constant. Should I take a global variable? Or can I do it with typedefs?

Eugen

Like Michael said, there is no such thing as global constants, but you can mimic this by creating VI for a system (global) constant.

In this VI put the system constants on the BD, then wire them to the indicators.

To access the "constant" values, just call the VI as usual, using the outputs as your constant values.

Or you can just use a FunctionalGlobal to store your global values.

/J

Share this post


Link to post
Share on other sites

Thank to all, I thought on

#define

in C/C++.

Is it possible to make something like this in LV?

Eugen

Share this post


Link to post
Share on other sites

Actually, if my understanding of C is correct, the #define directive only does a text substitution on your defined text. Since LV is strictly typed, what you're thinking of is "Const" which is typed.

In any case, as mentioned in the other thread I linked to (and here), you can't actually have consts today. You can either use the method described in the other thread (which has its advantages and disadvantages) or you can use a subVI, which is safer, but takes more work to create.

Share this post


Link to post
Share on other sites

Defines in C/C++ are replaced by a preprocessor before the code gets compiled.

Why not create a strict typedef ring containing all the values you need?

EDIT: this ofcouse only works when you don't have identical values...

VDB

Share this post


Link to post
Share on other sites

Now I think I understand. Is what you want basically an enum where you can control the numeric values (a sparse enum)?

This doesn't exist in LV, but as suggested you can use a typedef ring. Just note that the strings and values are not part of the data type of the ring, so updating the typedef does not update typedef constants. To update the BD constants, you need to change the type of the ring after you change its values. You can do this by changing its representation (e.g. I32 to U32) and then changing back and applying. This will cause the constants to reload the ring from the typedef.

If you want these as inputs to case structures, you can create a subVI which will translate your ring values to enum values.

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.