Structures for Disabling Code


If you have programmed in a text-based language, you have probably commented out blocks of code. For example, in C and Java, you can use the comment start (/*) and comment end (*/) strings to define a range of text that should not be executed. You can also use the line comment (//) string for commenting out entire lines of code. Shown next is a small snippet of code that uses both of these commenting techniques:

/* * This is an example showing * how to comment out text code */ if (foo > 1) {  // System.out.println("Hello World!"); } 



In LabVIEW, floating text placed on the block diagram does affect the functionality of the VIbecause LabVIEW is not a text-based language, floating text is ignored. However, for specifying portions of your graphical code that you do not want LabVIEW to execute, you can use the Diagram Disable and Conditional Disable structures. These can both be found in the Programming>>Structures subpalette of the Functions palette.

Just like a Case Structure, the Diagram Disable and Conditional Disable structures allow you to create several subdiagrams. However, you will notice that unlike the Case Structure, the Diagram Disable and Conditional Disable structures have no selector terminals for choosing which subdiagram LabVIEW will execute at run-time. This is because the one frame that LabVIEW is going to run is defined at edit-time. We will now discuss the way that the Diagram Disable and Conditional Disable structures decide which frame gets to run.

The Diagram Disable Structure

With the Diagram Disable structure, we can create multiple frames and name them anything we wish. And, we can define (at most) one frame that is enabled. You can enable a subdiagram by making the subdiagram visible and then right-clicking on the frame of the Diagram Disable structure and choosing Enable This Subdiagram from the shortcut menu. Similarly, you can disable a subdiagram by choosing Disable This Subdiagram from the shortcut menu. When you enable a subdiagram, all other subdiagrams will be disabled. Only one subdiagram can be enabled at a time. However, you do not have to have any subdiagrams enabled. If no subdiagram is enabled, then none of the subdiagrams will execute. You can tell which subdiagram (if any) is enabled from the pop-up menu on the subdiagram selectorthe subdiagram that is enabled will begin with an asterisk in square brackets ("[*]"), as shown in Figure 13.122.

Figure 13.122. Diagram Disable structure


By default, LabVIEW names the disabled subdiagrams "Disabled" and the enabled subdiagrams "Enabled." You can have several frames named "Disabled." Similarly, you can name several subdiagrams with the same nameunlike a Case Structure, LabVIEW will not complain about duplicate Diagram Disabled subdiagram names. If you do not change the subdiagram's name, LabVIEW will rename it when you change it from enabled to disabled and vice versa. However, LabVIEW will not rename any frames whose name you have changed. Remember, you can always tell which frame, if any, is enabled by the presence of "[*]" before its name.

Disabling code does not just prevent it from executing; LabVIEW doesn't even compile code in the "Disabled" subdiagrams. The usefulness of this is that any code in a "Disabled" subdiagram that is broken (or cannot be found) does not break our VI.

The Conditional Disable Structure

The Conditional Disable structure is slightly different from the Diagram Disable structure. The first difference is that LabVIEW will execute exactly one of the Conditional Disable structure subdiagramsthis subdiagram is referred to as the active subdiagram and the other subdiagrams are referred to as inactive subdiagrams. The second difference is that LabVIEW evaluates a condition (a conditional expression) to determine which frame will executeeach subdiagram's condition is shown as the title of that subdiagram, as shown in Figure 13.123.

Figure 13.123. Conditional Disable structure


A subdiagram's condition may be edited by selecting the subdiagram, and then right-clicking on the frame of the Conditional Disable structure and selecting Edit Condition for This Subdiagram from the shortcut menu. This will open the Configure Condition dialog, shown in Figure 13.124. From this dialog, you can edit the subdiagram's conditional expression.

Figure 13.124. Configure Condition dialog


For example, you can define one subdiagram with the condition "TARGET_ TYPE= =Windows" and another subdiagram with the condition "TARGET_TYPE = =Mac," in order to have a VI that executes differently on Windows than it does on the Mac. However, what LabVIEW does is more interesting than just deciding which code will execute on a given platform. LabVIEW only compiles the code in the active subdiagram (the subdiagram whose Condition evaluates to TRUE). The usefulness of this is that any code in an inactive subdiagram that is broken (or cannot be found) does not break our VI.

You might have noticed that the only symbol available is TARGET_TYPE. You can define other symbols in the LabVIEW Project environment; however, we will leave this as an exercise for the adventurous reader.





LabVIEW for Everyone. Graphical Programming Made Easy and Fun
LabVIEW for Everyone: Graphical Programming Made Easy and Fun (3rd Edition)
ISBN: 0131856723
EAN: 2147483647
Year: 2006
Pages: 294

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net