# Connexions

You are here: Home » Content » Case Structures

### Lenses

What is a lens?

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

#### Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
• NSF Partnership

This module is included inLens: NSF Partnership in Signal Processing
By: Sidney BurrusAs a part of collection: "LabVIEW Graphical Programming Course"

Click the "NSF Partnership" link to see all content affiliated with them.

Click the tag icon to display tags associated with this content.

• National Instruments

This module is included in aLens by: National InstrumentsAs a part of collection: "LabVIEW Graphical Programming Course"

"A full introductory course on programming with LabVIEW."

Click the "National Instruments" link to see all content affiliated with them.

Click the tag icon to display tags associated with this content.

#### Also in these lenses

• Lens for Engineering

This module is included inLens: Lens for Engineering
By: Sidney BurrusAs a part of collection: "LabVIEW Graphical Programming Course"

Click the "Lens for Engineering" link to see all content selected in this lens.

• eScience, eResearch and Computational Problem Solving

This module is included inLens: eScience, eResearch and Computational Problem Solving
By: Jan E. OdegardAs a part of collection: "LabVIEW Graphical Programming Course"

Click the "eScience, eResearch and Computational Problem Solving" link to see all content selected in this lens.

### Recently Viewed

This feature requires Javascript to be enabled.

### Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

# Case Structures

Module by: National Instruments. E-mail the author

Summary: In this lesson, you will learn how to use the Case structure.

A Case structure 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 case statements or if...then...else statements in text-based programming languages.

The case selector identifier at the top of the Case structure contains the case selector identifier in the center and decrement and increment buttons on each side. Use the decrement and increment buttons to scroll through the available cases.

Wire an input value, or selector, to the selector terminal 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 you wire a Boolean to the selector terminal, the structure has a True case and a False case. If you wire an integer, string, or enumerated type value to the selector terminal, the structure can have up to 2311 2 31 1 cases.

You can specify a default case for the Case structure. You must specify a default case to handle out-of-range values or explicitly list every possible input value. For example, if you specified cases for 1, 2, and 3 but you get an input of 4, the Case structure executes the default case.

You can specify a default case for the Case structure. You must specify a default case to handle out-of-range values or explicitly list every possible input value. For example, if you specified cases for 1, 2, and 3 but you get an input of 4, the Case structure executes the default case.

Right-click the Case structure border to add, duplicate, remove, or rearrange cases and to select a default case.

## Selecting a Case

The block diagram in Figure 1 is an example of the Thermometer VI that uses a Case structure instead of the Select function. It is shown with the True case foremost in the Case structure.

To select a case, type the value in the case selector identifier or use the Labeling tool to edit the values, as shown in the block diagram in Figure 2.

Once you have selected another case, that case appears foremost, as shown in the block diagram in Figure 3.

If you enter a selector value that is not the same type as the object wired to the selector terminal, the value appears red to indicate that you must delete or edit the value before the structure can execute, and the VI will not run. Also, because of the possible round-off error inherent in floating-point arithmetic, you cannot use floating-point numeric values as case selector values. If you wire a floating-point value to the case, LabVIEW rounds the value to the nearest even integer. If you type a floating-point value in the case selector, the value appears red to indicate that you must delete or edit the value before the structure can execute.

## Input and Output Tunnels

You can create multiple input and output tunnels for a Case structure. Inputs are available to all subdiagrams, but subdiagrams do not need to use each input. When you create an output tunnel in one case, corresponding tunnels appear at the same position on the border in all other cases.

If at least one output tunnel is not defined, all output tunnels on the structure appear as white squares. Wire to the output tunnel for each unwired case, clicking the tunnel each time. You can define a different data source for the same output tunnel in each case, but the data types must be compatible. You also can wire constants or controls to unwired cases by right-clicking the tunnel and selecting Create>>Constant or Create>>Control from the shortcut menu.

### Note:

You 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.

## Examples

In the following examples, the numeric values pass through tunnels to the Case structure and are either added or subtracted, depending on the value wired to the selector terminal.

### Example 1: Boolean Case Structure

The example in Figure 4 is a Boolean Case structure. The cases are shown overlapped to simplify the illustration.

If the Boolean control wired to the selector terminal is True, the VI adds the numeric values. Otherwise, the VI subtracts the numeric values.

### Example 2: Integer Case Structure

The example in Figure 5 is an integer Case structure.

Integer is a text ring control located on the Controls>>Text Controls palette that associates numeric values with text items. If the text ring control wired to the selector terminal is 0 (add), the VI adds the numeric values. If the value is 1 (subtract), the VI subtracts the numeric values. If the text ring control is any other value than 0 (add) or 1 (subtract), the VI adds the numeric values, because that is the default case.

### Example 3: String Case Structure

The example in Figure 6 is a string Case structure.

If String is add, the VI adds the numeric values. If String is subtract, the VI subtracts the numeric values.

### Example 4: Enumerated Case Structure

The example in Figure 7 is an enumerated Case structure.

An enumerated control gives users a list of items from which to select. The data type of an enumerated control includes information about the numeric values and string labels in the control. When you wire an enumerated control to the selector terminal of a Case structure, the case selector displays a case for each item in the enumerated control. The Case structure executes the appropriate case subdiagram based on the current item in the enumerated control. In the block diagram, if Enum is add, the VI adds the numeric values. If Enum is subtract, the VI subtracts the numeric values.

### Example 5: Error Case Structure

The example in Figure 8 is an error cluster Case structure.

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. The Case structure executes the appropriate case subdiagram based on the error state.

When an error cluster is wired to the selection terminal, the Case structure recognizes only the status Boolean of the cluster.

## Content actions

PDF | EPUB (?)

### What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks