Table Of Contents

Case Structure (G Dataflow)

Version:
Last Modified: September 13, 2017

Contains one or more subdiagrams, or cases, exactly one of which executes when the structure executes.

The value wired to the selector terminal determines which case to execute.

Case Structures behave similarly to switch statements or if-then-else statements in other programming languages.

Programming Patterns
terminal_icon

Selector

Value that determines which case to execute based on the input data. The input data can be a Boolean, string, integer, enumerated type, or error cluster. The data type you wire to the selector terminal determines what cases you can enter in the case selector label.

terminal_icon

Case Selector Label

Part of the structure that displays the value(s) for which the associated case executes.

You can specify a single value or a range of values. You can also use the case selector label to specify a default case.

terminal_icon

Tunnel

Point through which data enters or exits a structure.

Matching Cases from the Items in a Control

The Case Structure matches cases using different values depending on the data type of the input you wire to the selector terminal.
Input Data Type What Value do Cases Match? Comments
Ring Cases match the numeric values of items in the control rather than the string values. The Case Structure treats values from a ring control identically to a numeric control.
Enum Cases match the string values of items in the control rather than the numeric values. By default, an enum auto-populates the case selector label with the first two values from the items in the control. To create a case for every item in an enum control, right click the Case Structure and select Cases»Create Case for Every Value.
Combo Box Cases match the string values of items in the control. The Case Structure treats values from a combo box identically to values of a string control.

Entering Values in the Case Selector Label

You can enter a single value or lists and ranges of values in the case selector label of a Case Structure, as shown in the following table.

Type of Values Description
Numeric ranges Specify a range as 10..20, meaning all numbers from 10 to 20 inclusively.
Open-ended numeric ranges Specify a range as ..100, meaning all numbers less than or equal to 100, or 100.., meaning all numbers greater than or equal to 100.
Lists and ranges Use commas to separate values, for example ..5, 6, 7..10, 12, 13, 14.
String ranges

A range of a..c includes all strings beginning with a or b, but not c. If you want a case to execute for all strings beginning with a, b, and c, define the range as "a".."c", "c".

String ranges are case-sensitive by default. For example, a range of "A".."c" matches a different set of strings than "a".."c" because this structure uses ASCII values to determine a string range. In ASCII values, all capital letters have a lower numeric representation than all lower-case letters, so "A".."c" matches strings beginning with all capital letters A through Z, as well as lower case a and lower case b.

A string value accepts the following backslash codes for non-alphanumeric characters: \r for a carriage return, \n for a line feed, \t for a tab, and \s for a space.

Enumerated values 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 ".."). A string value accepts the following backslash codes for non-alphanumeric characters: \r for a carriage return, \n for a line feed, \t for a tab, and \s for a space.

Case Sensitivity in Strings

By default, string values in the case selector label are case-sensitive. You can disable case sensitivity by right-clicking the Case Structure and selecting Case Insensitive Match.

Requirements for Undefined Cases

An edit-time error occurs when there are values of the selector data type that do not correspond to any subdiagram in the Case Structure. You must either define a default case to handle out-of-range values or create a case for every possible input value. For example, if the selector is an integer data type 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.

Troubleshooting an Unexpected Execution of the Default Case

If the default case executes unexpectedly, verify that the input values wired to the selector terminal match the values in the case selector label exactly.

Search within the programming environment to access the following lesson: Case Structures

Search within the programming environment to access the following installed examples:

  • Simple Case Structure
  • State Machine Fundamentals

Where This Node Can Run:

Desktop OS: Windows

FPGA: DAQExpress does not support FPGA devices

Web Server: Supported in VIs that run in a web application


Recently Viewed Topics