<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="None">
  <name>Case Structures</name>
  <metadata>
  <md:version>1.1</md:version>
  <md:created>2004/06/23 12:31:40 GMT-5</md:created>
  <md:revised>2004/07/16 15:19:19.032 GMT-5</md:revised>
  <md:authorlist>
      <md:author id="NationalInstruments">
      <md:firstname>National</md:firstname>
      
      <md:surname>Instruments</md:surname>
      <md:email>certification@ni.com</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="lizzardg">
      <md:firstname>Elizabeth</md:firstname>
      
      <md:surname>Gregory</md:surname>
      <md:email>lizzardg@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="mshiralkar05">
      <md:firstname>Malan</md:firstname>
      
      <md:surname>Shiralkar</md:surname>
      <md:email>mshiralkar05@hotmail.com</md:email>
    </md:maintainer>
    <md:maintainer id="harika">
      <md:firstname>Harika</md:firstname>
      
      <md:surname>Basana</md:surname>
      <md:email>ilsai@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="NationalInstruments">
      <md:firstname>National</md:firstname>
      
      <md:surname>Instruments</md:surname>
      <md:email>certification@ni.com</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>National Instruments</md:keyword>
    <md:keyword>LabVIEW</md:keyword>
    <md:keyword>case structure</md:keyword>
  </md:keywordlist>

  <md:abstract>In this lesson, you will learn how to use the Case structure.</md:abstract>
</metadata>

  <content>
    <para id="p1">
      <media type="image/png" src="case.png"/> A <code>Case</code>
      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 <code>Case</code> structure is similar to case
      statements or if...then...else statements in text-based
      programming languages.
    </para>
    <para id="p2">
      <media type="image/png" src="caseid.png"/> The <code>case
      selector identifier</code> at the top of the <code>Case</code>
      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.
    </para>
    <para id="p3">
      <media type="image/png" src="selectcase.png"/> Wire an input
      value, or selector, to the <code>selector terminal</code> 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 <code>Case</code> structure. If you wire a
      Boolean to the selector terminal, the structure has a
      <code>True</code> case and a <code>False</code> case. If you
      wire an integer, string, or enumerated type value to the
      selector terminal, the structure can have up to
      <m:math>
	<m:apply>
	  <m:minus/>
	  <m:apply>
	    <m:power/>
	    <m:cn>2</m:cn>
	    <m:cn>31</m:cn>
	  </m:apply>
	  <m:cn>1</m:cn>
	</m:apply>
      </m:math> cases.
    </para>
    <para id="p4">
      You can specify a default case for the <code>Case</code>
      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 <code>Case</code> structure executes
      the default case.
    </para>
    <para id="p5">
      You can specify a <code>default</code> case for the Case
      structure. You must specify a <code>default</code> case to
      handle out-of-range values or explicitly list every possible
      input value. For example, if you specified cases for
      <code>1</code>, <code>2</code>, and <code>3</code> but you get
      an input of <code>4</code>, the Case structure executes the
      <code>default</code> case.
    </para>
    <para id="p6">
      Right-click the <code>Case</code> structure border to add,
      duplicate, remove, or rearrange cases and to select a
      <code>default</code> case.
    </para>
    <section id="s1">
      <name>Selecting a Case</name>
      <para id="s1p1">
	The block diagram in <cnxn target="s1f1"/> is an example of
	the <cnxn document="m12209">Thermometer VI</cnxn> that uses a
	<code>Case</code> structure instead of the <code>Select</code>
	function. It is shown with the <code>True</code> case foremost
	in the <code>Case</code> structure.
      </para>
      <figure id="s1f1">
	<media type="image/png" src="thermocaseT.png"/>
      </figure>
      <para id="s1p2">
	To select a case, type the value in the case selector
	identifier or use the <code>Labeling</code> tool to edit the
	values, as shown in the block diagram in <cnxn target="s1f2"/>.
      </para>
      <figure id="s1f2">
	<media type="image/png" src="thermocasechoose.png"/>
      </figure>
      <para id="s1p3">
	Once you have selected another case, that case appears
	foremost, as shown in the block diagram in <cnxn target="s1f3"/>.
      </para>
      <figure id="s1f3">
	<media type="image/png" src="thermocaseF.png"/>
      </figure>
      <para id="s1p4">
	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.
      </para>
    </section>
    <section id="s2">
      <name>Input and Output Tunnels</name>
      <para id="s2p1">
	You can create multiple input and output tunnels for a
	<code>Case</code> 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.
      </para>
      <para id="s2p2">
	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
	<code>Create&gt;&gt;Constant</code> or <code>Create&gt;&gt;Control</code>
	from the shortcut menu.
      </para>
      <note>
	You can right-click the output tunnel and select <code>Use
	Default If Unwired</code> from the shortcut menu to use the
	default value for the tunnel data type for all unwired
	tunnels.
      </note>
    </section>
    <section id="s3">
      <name>Examples</name>
      <para id="s3p1">
	In the following examples, the numeric values pass through
	tunnels to the <code>Case</code> structure and are either
	added or subtracted, depending on the value wired to the
	selector terminal.
      </para>
      <example id="s3ex1">
	<name>Boolean Case Structure</name> 
	<para id="s3ex1p1">
	  The example in <cnxn target="s3ex1f1"/> is a Boolean
	  <code>Case</code> structure. The cases are shown overlapped
	  to simplify the illustration.
	</para>
	<figure id="s3ex1f1">
	  <media type="image/png" src="boolcase.png"/>
	</figure>
	<para id="s3ex1p2">
	  If the Boolean control wired to the selector terminal is
	  <code>True</code>, the VI adds the numeric
	  values. Otherwise, the VI subtracts the numeric values.
	</para>
      </example>
      <example id="s3ex2">
	<name>Integer Case Structure</name>
	<para id="s3ex2p1">
	  The example in <cnxn target="s3ex2f1"/> is an integer Case
	  structure.
	</para>
	<figure id="s3ex2f1">
	  <media type="image/png" src="intcase.png"/>
	</figure>
	<para id="s3ex2p2">
	  <code>Integer</code> is a text ring control located on the
	  <code>Controls&gt;&gt;Text Controls</code> palette that associates
	  numeric values with text items. If the text ring control
	  wired to the selector terminal is <code>0</code>
	  (<code>add</code>), the VI adds the numeric values. If the
	  value is <code>1</code> (<code>subtract</code>), the VI
	  subtracts the numeric values. If the text ring control is
	  any other value than <code>0</code> (<code>add</code>) or
	  <code>1</code> (<code>subtract</code>), the VI adds the
	  numeric values, because that is the <code>default</code>
	  case.
	</para>
      </example>
      <example id="s3ex3">
	<name>String Case Structure</name>
	<para id="s3ex3p1">
	  The example in <cnxn target="s3ex3f1"/> is a string
	  <code>Case</code> structure.
	</para>
	<figure id="s3ex3f1">
	  <media type="image/png" src="stringcase.png"/>
	</figure>
	<para id="s3ex3p2">
	  If <code>String</code> is <code>add</code>, the VI adds the
	  numeric values. If <code>String</code> is
	  <code>subtract</code>, the VI subtracts the numeric values.
	</para>
      </example>
      <example id="s3ex4">
	<name>Enumerated Case Structure</name>
	<para id="s3ex4p1">
	  The example in <cnxn target="s3ex4f1"/> is an enumerated
	  <code>Case</code> structure.
	</para>
	<figure id="s3ex4f1">
	  <media type="image/png" src="enumcase.png"/>
	</figure>
	<para id="s3ex4p2">
	  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 <code>Case</code> structure, the case
	  selector displays a case for each item in the enumerated
	  control. The <code>Case</code> structure executes the
	  appropriate case subdiagram based on the current item in the
	  enumerated control. In the <cnxn target="s3ex4f1">block
	  diagram</cnxn>, if <code>Enum</code> is <code>add</code>,
	  the VI adds the numeric values. If <code>Enum</code> is
	  <code>subtract</code>, the VI subtracts the numeric values.
	</para>
      </example>
      <example id="s3ex5">
	<name>Error Case Structure</name>
	<para id="s3ex5p1">
	  The example in <cnxn target="s3ex5f1"/> is an error cluster
	  <code>Case</code> structure.
	</para>
	<figure id="s3ex5f1">
	  <media type="image/png" src="errorcase.png"/>
	</figure>
	<para id="s3ex5p2">
	  When you wire an error cluster to the selector terminal of a
	  <code>Case</code> structure, the case selector label
	  displays two cases, <code>Error</code> and <code>No
	  Error</code>, and the border of the <code>Case</code>
	  structure changes color--red for <code>Error</code> and
	  green for <code>No Error</code>. The <code>Case</code>
	  structure executes the appropriate case subdiagram based on
	  the error state.
	</para>
	<para id="s3ex5p3">
	  When an error cluster is wired to the <code>selection</code>
	  terminal, the <code>Case</code> structure recognizes only
	  the <code>status</code> Boolean of the cluster.
	</para>
      </example>
    </section>
      
  </content>
  
</document>
