Jump to content

Case structure: Difference between revisions

From LabVIEW Wiki
Line 47: Line 47:
*Selection is by default done ''case sensitive'', to make the selection ''case insensitive'' right click on the selector label and select ''Case insensitive match''
*Selection is by default done ''case sensitive'', to make the selection ''case insensitive'' right click on the selector label and select ''Case insensitive match''
*A default case is obliged
*A default case is obliged
*Ranges
*Ranges<br/>Just like integer and enum case structures a string case structure accepts ranges. To detect all string starting with foo the following range would apply ''"foo".."foo~"''. By adding the tilde on the end of the range you will get all strings starting with foo up to foo~. The tilde is the last visible ASCII character.
:Just like integer and enum case structures a string case structure accepts ranges. To detect all string starting with foo the following range would apply ''"foo".."foo~"''. By adding the tilde on the end of the range you will get all strings starting with foo up to foo~. The tilde is the last visible ASCII character.


===Error===
===Error===

Revision as of 11:38, 8 December 2008

Introduction

A case structure is a LabVIEW primitive that dynamically selects which parts of code should execute.

General Items

On compile time the compiler assures that at least one case will run when the code executes, if this cannot be determined the containing VI will be broken. To provide a case for values of the selector that is general a case can be labeled default. One case can be used to handle several selector values. To enter these provide a , between the values. A range of these values can be set by providing .. between the values.

Selection mechanism

The selection decision of the case structure can be done by several datatypes:

  • Boolean
  • Integer
  • Enum
  • String
  • Error Cluster

Boolean

The boolean case structure is the default state of the case structure. It has a case for the True and the False state.

Integer

The integer case structure uses the integer value of the selector data type to determine which case is executed

Floats

Non-integer numerics (floats) are rounded according IEEE 754-1985 where a non-integer is rounded to the nearest even integer.

Tricks

  • Ranges
An integer case structure accepts ranges to limit the number of cases. These ranges can be closed (3..10) or open (3..) where every value above 2 is executed.

Enum

The enum case structure uses the string interpretation of the value to label the cases.

Tricks

  • To have a case for every enum value right click on the selector label of the case structure and select add case for every value.
  • Don't add a default case, if the enum datatype changes the code will break and you'll be triggered that a case should be added

String

The string case structure uses the string value to select which case should execute.

Tricks

  • Selection is by default done case sensitive, to make the selection case insensitive right click on the selector label and select Case insensitive match
  • A default case is obliged
  • Ranges
    Just like integer and enum case structures a string case structure accepts ranges. To detect all string starting with foo the following range would apply "foo".."foo~". By adding the tilde on the end of the range you will get all strings starting with foo up to foo~. The tilde is the last visible ASCII character.

Error

The error case structure is like the boolean case structure but can be controlled by the error state of an error cluster. The border of the error case is red and the non-error case is green.