Eugen Graf Posted May 12, 2007 Report Share Posted May 12, 2007 Hello, how can I create a global constant. Should I take a global variable? Or can I do it with typedefs? Eugen Quote Link to comment
Michael Aivaliotis Posted May 12, 2007 Report Share Posted May 12, 2007 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. Quote Link to comment
Yair Posted May 12, 2007 Report Share Posted May 12, 2007 You might wish to read this thread. For some things, if you're using a subVI, you won't even need a typedef. Quote Link to comment
Mellroth Posted May 12, 2007 Report Share Posted May 12, 2007 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 Quote Link to comment
Eugen Graf Posted May 12, 2007 Author Report Share Posted May 12, 2007 Thank to all, I thought on #define in C/C++. Is it possible to make something like this in LV? Eugen Quote Link to comment
Yair Posted May 12, 2007 Report Share Posted May 12, 2007 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. Quote Link to comment
Eugen Graf Posted May 12, 2007 Author Report Share Posted May 12, 2007 Here an example what I opine. Eugen Quote Link to comment
Yair Posted May 12, 2007 Report Share Posted May 12, 2007 Did you read the other thread? Quote Link to comment
VDB Posted May 12, 2007 Report Share Posted May 12, 2007 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 Quote Link to comment
Yair Posted May 12, 2007 Report Share Posted May 12, 2007 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. Quote Link to comment
Eugen Graf Posted May 12, 2007 Author Report Share Posted May 12, 2007 Yes, thank to all, I understood all, what was needed. Eugen Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.