LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use in enums in multiple places?

How does one use an enum set in multiple places in a vi?

I have resorted to just copying an existing one when I need the same set of enum values in a different spot, but doing it this way will be a big hassle if/when I want to add items to the enum, because I would have to locate every copy of the enum and update them idividually.

Is it possible?
0 Kudos
Message 1 of 14
(4,884 Views)
what you need to do is create a custom control, a strict type def, and create your enum as the control object; every where you want to refer to the enum, place an instance of the custom control on your front panel. Every control based on the custom control, and any constants you place in diagrams created from such a control, can be automatically updated if you "redesign" the enum definition in the custom control itself...
0 Kudos
Message 2 of 14
(4,879 Views)
How does "strict type def." differ from "type def."?  You state that a strict type def. should be used.  When I took LV Intermediate 1 & 2, the course manual says a type def. should be used.
 
Which should be used in this case, and what are the advantages or disadvantages of using one or the other?
 
Thanks,
Bill
0 Kudos
Message 3 of 14
(4,872 Views)

A strict typedef enforces the appearance and properties (range, etc.) of the control as well as the type. The help should have more details.

Note - while a regular typedef allow you to change the appearance of each instance, updating the typedef will make all instances look like the new typedef, making you lose your changes.


___________________
Try to take over the world!
0 Kudos
Message 4 of 14
(4,867 Views)
Tst,
 
Thanks for the info.  That helped clarify strict vs. regular for me.  I imagine in a case using Enums where you are using it as a method for control a state machine, or different cases of a functional global variable, it probably wouldn't matter which is used, as you aren't concerned about appearance, but just using a common, easily updated list throughout the block diagram.
 
I guess the strict vs. regular decision becomes critical for mulitple copies of front panel objects where you may or may not want the user to have too much control over the modifying the various properties of the control.
0 Kudos
Message 5 of 14
(4,863 Views)
Hmmm.

Well, I don't want a front panel control, I want soemthing I can place on a block diagram to use as a case selector, which is what a plain old enum (not an enum control) is good for.

In C, I could just define an enum set somewhere in a .h file, then use it wherever.

Will creating a custom control do what I want?

Sorry if what I want to do is obvious. I'm a newbie.
0 Kudos
Message 6 of 14
(4,861 Views)
I'm sorry..

I DON'T want to use the enum as a case selector.

I want to use it where I need to assign a constant value.
0 Kudos
Message 7 of 14
(4,859 Views)
We talk about custom controls, but that doesn't mean you are forced to put a control on the front panel.  Here is the basic procedure.
 
1. Create an Enum control on the front panel (it's only temporary).
2.  Edit it to add the various items that you want.
3.  Right click the control on the front panel.  Pick advanced >> customize.
4.  Change the drop down from Control to Type Def.  (or possibly Strict Type Def.)
5. Save the control as a .ctl file.
6.  Close the control editor.
7.  Delete the control.
8.  Drag the copy of the .ctl file onto the block diagram.  It will go in as a constant.
9.  Now you can use that and copy it wherever.
10.  If you need to add a new item.  Open the .ctl file, add the new item and save it.  It will be updated everywhere in the VI.
Message 8 of 14
(4,853 Views)

It's not so much the "custom control" part as it is the typedef part. A typedef enforces the datatype for all its instances, including constants, so changing it will propogate through your entire code. To create it the easiest way is to create a front panel enum control and then right click it and select Advanced>>Customize. You can then change it into a typedef and save it under any name you want.

From this point on, you can simply use that typedef in your code.

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here, here, here, here and here are a few you can start with and here are some tutorial videos. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).


___________________
Try to take over the world!
0 Kudos
Message 9 of 14
(4,851 Views)

The enum will be a constant within the block diagram.  You can have one or multiple items in the drop down list based on what items are saved in the .ctl file.

If you edit the .ctl file to add, subtract, or change an item, the changes get updated wherever the file was used to create the constants.  So you only have to make one modification, instead of tracking down numerous places it was used.

0 Kudos
Message 10 of 14
(4,848 Views)