Jump to content

Global constants


Recommended Posts

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

Link to comment

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.

Link to comment

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

Link to comment

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.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.