|Download Help (Windows Only)|
Case, Stacked Sequence, Flat Sequence, and Event structures contain multiple subdiagrams. A Case structure executes one subdiagram depending on the input value passed to the structure. A Stacked Sequence structure and a Flat Sequence structure execute all their subdiagrams in sequential order. An Event structure executes its subdiagrams depending on how the user interacts with the VI.
A Case structure, shown as follows, has two or more subdiagrams, or cases.
Only one subdiagram is visible at a time, and the structure executes only one case at a time. An input value determines which subdiagram executes. The Case structure is similar to switch statements or if...then...else statements in text-based programming languages.
The case selector label at the top of the Case structure, shown as follows, contains the name of the selector value that corresponds to the case in the center and decrement and increment arrows on each side.
Click the decrement and increment arrows to scroll through the available cases. You also can click the down arrow next to the case name and select a case from the pull-down menu.
Wire an input value, or selector, to the selector terminal, shown as follows, to determine which case executes.
You must wire an integer, Boolean value, string, or enumerated type value to the selector terminal. You can position the selector terminal anywhere on the left border of the Case structure. If the data type of the selector terminal is Boolean, the structure has a True case and a False case. If the selector terminal is an integer, string, or enumerated type value, the structure can have any number of cases.
|Note By default, string values you wire to the selector terminal are case sensitive. To allow case-insensitive matches, wire a string value to the selector terminal, right-click the border of the Case structure, and select Case Insensitive Match from the shortcut menu.|
If you do not specify a default case for the Case structure to handle out-of-range values, you must explicitly list every possible input value. For example, if the selector is an integer and you specify cases for 1, 2, and 3, you must specify a default case to execute if the input value is 4 or any other unspecified integer value.
|Note You cannot specify a default case if you wire a Boolean control to the selector. If you right-click the case selector label, Make This The Default Case does not appear in the shortcut menu. Make the Boolean control TRUE or FALSE to determine which case to execute.|
To convert a Case structure to a Stacked Sequence structure, right-click the Case Sequence structure and select Replace with Stacked Sequence from the shortcut menu.
You can enter a single value or lists and ranges of values in the case selector label. For lists, use commas to separate values. For numeric ranges, specify a range as 10..20, meaning all numbers from 10 to 20 inclusively. You also can use open-ended ranges. For example, ..100 represents all numbers less than or equal to 100, and 100.. represents all numbers greater than or equal to 100. You also can combine lists and ranges, for example ..5, 6, 7..10, 12, 13, 14. When you enter values that contain overlapping ranges in the same case selector label, the Case structure redisplays the label in a more compact form. The previous example redisplays as ..10, 12..14. For string ranges, a range of a..c includes all strings beginning with of a or b, but not c. A range of a..c,c includes the ending value of c.
|Note String ranges are case sensitive. For example, a range of A..c will behave differently than a..c because LabVIEW uses ASCII values to determine a string range.|
When you enter string and enumerated values in a case selector label, the values display in quotation marks, for example "red", "green", and "blue". However, you do not need to type the quotation marks when you enter the values unless the string or enumerated value contains a comma or range symbol ("," or ".."). In a string value, use special backslash codes for non-alphanumeric characters, such as \r for a carriage return, \n for a line feed, and \t for a tab.
If you change the data type of the wire connected to the selector terminal of a Case structure, the Case structure automatically converts the case selector values to the new data type when possible. If you convert a numeric value, for example 19, to a string, the string value is “19”. If you convert a string to a numeric value, LabVIEW converts only those string values that represent a number. The other values remain strings. If you convert a number to a Boolean value, LabVIEW converts 0 to False and 1 to True, and all other numeric values become strings.
|Note You cannot use fixed-point numbers as case selector values. If you wire a fixed-point number to the case, the VI appears with a broken Run button.|
If you enter a selector value that is not the same type as the object wired to the selector terminal, the value appears red. This indicates that the VI will not run until you delete or edit the value. Also, because of the possible round-off error inherent in floating-point arithmetic, you cannot use floating-point numbers as case selector values. If you wire a floating-point value to the case, LabVIEW rounds the value to the nearest integer. If you type a floating-point value in the case selector label, the value appears red to indicate that you must delete or edit the value before the structure can execute.
You can create multiple input and output tunnels for a Case structure. Inputs are available to all cases, but cases do not have to use each input. However, you must define each output tunnel for each case. When you create an output tunnel in one case, tunnels appear at the same position on the border in all the other cases. If even one output tunnel is not wired, all output tunnels on the structure appear as white squares. You can define a different data source for the same output tunnel in each case, but the data types must be compatible for each case. Consider configuring the tunnels on a structure to wire the input and output tunnels automatically in unwired cases. You also can right-click the output tunnel and select Use Default If Unwired from the shortcut menu to use the default value for the tunnel data type for all unwired tunnels. However, the best practice is to configure the tunnels on a structure to wire the input and output tunnels automatically in unwired cases.
When you wire an error cluster to the selector terminal of a Case structure, the case selector label displays two cases—Error and No Error—and the border of the Case structure changes color—red for Error and green for No Error. If an error occurs, the Case structure executes the Error subdiagram.
A sequence structure contains one or more subdiagrams, or frames, that execute in sequential order. Within each frame of a sequence structure, as in the rest of the block diagram, data dependency determines the execution order of nodes.
There are two types of sequence structures—the Flat Sequence structure and the Stacked Sequence structure. Use sequence structures sparingly because they hide code. Rely on data flow rather than sequence structures to control the order of execution. With sequence structures, you break the left-to-right data flow paradigm whenever you use a sequence local variable.
|Tip To help control data flow, you can use error clusters instead. If flow-through parameters are not available and you must use a sequence structure in a VI, consider using a Flat Sequence structure. Refer to the LabVIEW Style Checklist for more tips on when to use sequence structures.|
The Flat Sequence structure, shown as follows, executes frames from left to right and when all data values wired to a frame are available. The data leaves each frame as the frame finishes executing. This means the input of one frame can depend on the output of another frame.
Unlike in the Stacked Sequence structure, you do not need to use sequence locals to pass data from frame to frame in the Flat Sequence structure. Since the Flat Sequence structure displays each frame on the block diagram, you can wire from frame to frame without sequence locals and without hiding code.
When you add or delete frames in a Flat Sequence structure, the structure resizes automatically.
To convert a Flat Sequence structure to a Stacked Sequence structure, right-click the Flat Sequence structure and select Replace with Stacked Sequence from the shortcut menu. If you change a Flat Sequence to a Stacked Sequence and then back to a Flat Sequence, LabVIEW moves all input terminals to the first frame of the sequence. The final Flat Sequence operates the same as the Stacked Sequence. After you change the Stacked Sequence to a Flat Sequence with all input terminals on the first frame, you can move wires to where they were located in the original Flat Sequence.
(Windows, ETS, VxWorks) To convert a Flat Sequence structure to a Timed Sequence structure, right-click the Flat Sequence structure and select Replace with Timed Sequence from the shortcut menu.
The Stacked Sequence structure, shown as follows, stacks each frame so you see only one frame at a time and executes frame 0, then frame 1, and so on until the last frame executes.
The Stacked Sequence structure returns data only after the last frame executes. Use the Stacked Sequence structure if you want to conserve space on the block diagram.
To convert a Stacked Sequence structure to a Flat Sequence structure, right-click the Stacked Sequence structure and select ReplaceğReplace with Flat Sequence from the shortcut menu. To convert a Stacked Sequence structure to a Case structure, right-click the Stacked Sequence structure and select ReplaceğReplace with Case Structure from the shortcut menu.
The sequence selector identifier, shown as follows, at the top of the Stacked Sequence structure contains the current frame number and range of frames.
Use the sequence selector identifier to navigate through the available frames and rearrange frames. The frame label in a Stacked Sequence structure is similar to the case selector label of the Case structure. The frame label contains the frame number in the center and decrement and increment arrows on each side. Click the decrement and increment arrows to scroll through the available frames. You also can click the down arrow next to the frame number and select a frame from the pull-down menu. Right-click the border of a frame, select Make This Frame, and select a frame number from the shortcut menu to rearrange the order of a Stacked Sequence structure.
Unlike the case selector label, you cannot enter values in the frame label. When you add, delete, or rearrange frames in a Stacked Sequence structure, LabVIEW automatically adjusts the numbers in the frame labels.
To pass data from one frame to any subsequent frame of a Stacked Sequence structure, use a sequence local terminal, shown as follows. To add a sequence local terminal, right-click the structure border and select Add Sequence Local.
An outward-pointing arrow appears in the sequence local terminal of the frame that contains the data source. The terminal in subsequent frames contains an inward-pointing arrow, indicating that the terminal is a data source for that frame. You cannot use the sequence local terminal in frames that precede the first frame where you wired the sequence local.
The tunnels of a sequence structure can have only one data source, unlike Case structures. The output can emit from any frame. If you use a Flat Sequence structure, the data from outside the sequence structure enters the frame as each frame executes. The data leaves the frame after the frame executes. If you use a Stacked Sequence structure, the structure does not start to execute until all data wired to the structure arrives. The data wired from each frame leaves only when all the frames complete execution. As with Case structures, data at input tunnels is available to all frames in either the Flat Sequence or the Stacked Sequence structure.
To pass data from one frame to any subsequent frame in a Flat Sequence structure, wire from the tunnel of one frame to any other frame in the structure. You can wire through a frame or out of one frame and into another frame.
Refer to the labview\examples\general\structs.llb for examples of using sequence structures.
To take advantage of the inherent parallelism in LabVIEW, avoid overusing sequence structures. Sequence structures guarantee the order of execution and prohibit parallel operations. For example, asynchronous tasks that use I/O devices, such as PXI, GPIB, serial ports, and DAQ devices, can run concurrently with other operations if sequence structures do not prevent them from doing so.
Also, you cannot update an indicator from multiple frames of the sequence structure, as shown in the following illustration.
In the illustration, a VI used in a test application has a Status indicator that displays the name of the current test in progress. If each test is a subVI called from a different frame, you cannot update the indicator from each frame, as shown by the broken wire in the Stacked Sequence structure. Because all frames of a Stacked Sequence structure execute before any data passes out of the structure, only one frame can assign a value to the Status indicator.
Instead, use a Case structure and a While Loop, as shown in the following block diagram.
Each case in the Case structure is equivalent to a sequence structure frame. Each iteration of the While Loop executes the next case. The Status indicator displays the status of the VI for each case. Because data passes out of the structure after each case executes, the Status indicator is updated in the case before the one that calls the corresponding subVI.
Unlike a sequence structure, a Case structure can pass data to end the While Loop during any case. For example, if an error occurs while running the first test, the Case structure can pass FALSE to the conditional terminal to end the loop. However, a sequence structure must execute all its frames even if an error occurs.