HomeModules Module 1.7 (LabView Case Structures) Connect
I ntroduce
C onnect
A pply
R eflect
E xtend

Connect - LabView
Case Structures

Case Structures

Definition

The Case Structure is a method of executing conditional statements. The Case Structure is similar to if . . then . . else statements in conventional programming languages. Below is the pseudo code:
If (Condition = Something) then
Do This

Else

Do That

Endif

 

 

 

 

 

 

 

 

Below is a labeled example of a Case Structure defining the key terms:

The Labview Case Structure is configured like a deck of cards. Each "card" is a case in the case structure and each case contains a a subdiagram. You only see one case and subdiagram at a time and Labview only executes one at a time. Which case executes is determined by the value wired to the selector terminal ()on the left side of the Case Structure.


Case Structure Data Types

The data type wired to the selector terminal can be numeric, Boolean, or string. By default, Case Structures are set to Boolean but automatically adapt to the data type wired to the selector terminal. Below are examples of three Case Structures with the three different data types wired to to the selector terminal. The cases have been separated in this image to better show their structure.

 

A few things to remember about Case Structures and their data types:

  • If the data type is Boolean, the structure can only have two cases: True or False.
  • If the data type is numeric or string, the structure can have up to 231 - 1 cases.
  • If the data type is numeric or string, the top or first case will have "default" in the menu at the top of the Case Structure.
  • If the data type is numeric, use integer values. All floating-point numbers are converted to integers and negative numbers are converted to zero.
  • If the data type is string, the data values must be in quotes.
  • Each case must have a subdiagram of some kind.
  • If any case outputs data, all cases must output data through the output tunnel.
Below is an example of a simple Case Structure Application for an add or subtract VI. There is a Boolean Control applied to the selector terminal, so the Case Structure is the Boolean data type. When the Boolan control on the Front Panel is in the up position, it returns a FALSE to the selector terminal which invokes the subtract case.

When the Boolean control is put in the down position, it returns a TRUE value to the selector terminal which invokes the add case.

Notice the correct answer in the Result Indicator in each case.


Creating a Case Structure

Creating a Case Structure is much like creating While Loops and For Loops. To create a Case Structure, Pop-up in the Block Diagram > Structures > Case Structure. Drag an area for the Case Structure to encompass.

Managing Case Structures

Case structures can be managed in two ways. The first way is with the Case Structure Pop-up shown below. The pop-up menu allows you to move between cases, add cases, delete cases, go directly to a case, move subdiagrams between cases and even rearrange cases:

The second way to manage a Case Structure is with the menu at the top of the Case Structure loop. This menu allows you to go to the next or previous subdiagram by clicking on the Decrement or Increments at the left and right sides of the menu respectively. You can also click on the subdiagram title. This gives you a list of all subdiagrams and the ability to jump immediately to any desired subdiagram.


The Select Function

Definition

In simple if-then-else cases, you can use the Select function:

This function:

  • Returns the value wired to the t terminal if the value at the s terminal is TRUE
  • Returns the value wired to the f terminal if the value at the s terminal is FALSE.

 

Click here to move on to the next section (Apply).