<?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>Auto Match VI</name>
  <metadata>
  <md:version>1.3</md:version>
  <md:created>2004/06/18 13:14:42 GMT-5</md:created>
  <md:revised>2007/07/19 09:36:10.407 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="NationalInstruments">
      <md:firstname>National</md:firstname>
      
      <md:surname>Instruments</md:surname>
      <md:email>certification@ni.com</md:email>
    </md:maintainer>
    <md:maintainer id="lizzardg">
      <md:firstname>Elizabeth</md:firstname>
      
      <md:surname>Gregory</md:surname>
      <md:email>elizabeth.gregory@gmail.com</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:maintainerlist>
  
  

  <md:abstract>To pass data out of a While Loop through a tunnel.</md:abstract>
</metadata>
  
  <content>
    <exercise id="e1">
      <problem>
	<para id="delete_me">
	  Complete the following steps to build a VI that generates random
	  numbers until the number generated matches a number you
	  specify. The <code>iteration </code> terminal records the number
	  of random numbers generated until a match occurs.  
	</para>
	
	
	<section>
	  <name>Front Panel</name>
	  <list id="scream1" type="enumerated">
	    <item>
	      Open a blank VI and build the front panel shown in <cnxn target="dida"/>. Modify the controls and indicators as
	      shown in the <cnxn target="dida">front panel</cnxn> and
	      as described in the following <cnxn target="seren1">steps</cnxn>.
	      <figure id="dida">
		<media type="image/png" src="automatch.png"/>
	      </figure>
	      
	      <list id="seren1" type="enumerated">
		<item>
		  Place a numeric control, located on the
		  <code>Controls&gt;&gt;Numeric Controls</code> palette, on the
		  front panel. Label the control <code>Number to
		    Match</code>. This control specifies the number to
		  match.
		</item>
		
		<item>
		  Place a numeric indicator, located on the
		  <code>Controls&gt;&gt;Numeric Indicators </code> palette, on
		  the front panel. Label the indicator <code>Current
		    Number</code>. This indicator displays the current
		  random number.
		</item>
		
		<item>
		  Place another numeric indicator on the front
		  panel. Label the indicator <code>Number of
		    iterations</code>. This indicator displays the number of
		  iterations before a match.
		</item>
	      </list>
	    </item>
	  </list> 
	</section>
	
	<section>
	  <name>Setting the Data Range</name>
	  <para id="saved1">
	    Set a data range for a control to prevent the user from
	    selecting a value that is not compatible with a range or
	    increment. You can choose to ignore a value that is out of
	    range or coerce it to within the range. Complete the following
	    <cnxn target="scream2">steps</cnxn> to set the range between
	    <code>0</code> and <code>10000</code> with an increment of
	    <code>1</code> and a default value of <code>50</code>.
	  </para>
	  
	  <list id="scream2" type="enumerated">
	    <item>
	      Right-click the <code>Number to Match</code> control and
	      select <code>Data Range</code> from the shortcut menu. The
	      <code>Data Range</code> page of the <code>Numeric
		Properties</code> dialog box appears.
	      <list id="seren2" type="enumerated">
		
		<item> 
		  Remove the checkmark from the <code>Use Default
		    Range</code> checkbox.
		</item>
		
		<item>
		  Set the <code>Default Value</code> to <code>50</code>.
		</item>
		
		<item>
		  Set the <code>Minimum value</code> to <code>0</code> and
		  select <code>Coerce</code> from the <code>Out of Range
		    Action</code> pull-down menu.
		</item>
		
		<item>
		  Set the <code>Maximum value</code> to <code>10000</code>
		  and select <code>Coerce</code> from the <code>Out of
		    Range Action</code> pull-down menu.
		</item>
		
		<item>
		  Set the <code>Increment</code> value to <code>1</code>
		  and select <code>Coerce to Nearest</code> from the
		  <code>Out of Range Action</code> pull-down menu. Do
		  not close the dialog box.
		</item>
	      </list>
	    </item>
	  </list> 
	</section>
	
	
	<section>
	  <name>Modifying Digits of Precision</name>
	  <para id="saved2">
	    By default, LabVIEW automatically formats numeric
	    controls. You also can specify the precision or notation. You
	    can display numeric values in floating-point, scientific, or
	    SI notation. Complete the following steps to change the
	    precision to <code>0</code>.
	  </para>
	  
	  <list id="scream3" type="enumerated"><item>
	      Select the <code>Format and Precision</code> tab.  If you
	      closed the <code>Numeric Properties</code> dialog box,
	      right-click the <code>Current Number</code> indicator and
	      select <code>Format &amp; Precision</code> from the shortcut
	      menu. The <code>Format &amp; Precision</code> page of the
	      <code>Numeric Properties</code> dialog box appears.
	      
	      <list id="saint1" type="enumerated"> 
		<item>
		  Select <code>Floating Point</code> and change
		  <code>Significant digits</code> to <code>Digits of
		    precision</code>.
		</item>
		
		<item>
		  Type <code>0</code> in the <code>Digits of
		    precision</code> text box and click the <code>OK</code>
		  button.
		</item>
	      </list>
	    </item>
	    
	    <item> 
	      Repeat the instructions to set the precision for
	      <code>Current Number</code> and <code>Number of
		iterations</code> indicators.
	    </item>
	  </list> 
	</section>
	
	<section>
	  <name>Block Diagram</name>
	  <list id="scream4" type="enumerated">
	    <item>
	      Build the block diagram in <cnxn target="ladi"/>.
	      <figure id="ladi">
		<media type="image/png" src="automatchbd.png"/>
	      </figure>
	      
	      <list id="saint2" type="enumerated"><item>
		  <media type="image/png" src="randnum.png"/> 
		  Place the <code>Random Number (0-1)</code> function,
		  located on the <code>Functions&gt;&gt;Arithmetic &amp;
		    Comparison&gt;&gt;Express Numeric </code> palette, on the
		  block diagram. This function produces a random number
		  between <m:math><m:cn>0</m:cn></m:math> and
		  <m:math><m:cn>1</m:cn></m:math>.
		</item>
		<item>
		  <media type="image/png" src="multiply.png"/>
		  Place the <code>Multiply</code> function, located on the
		  <code>Functions&gt;&gt;Arithmetic &amp; Comparison&gt;&gt;Express
		    Numeric</code> palette, on the block diagram. This
		  function multiplies the random number by
		  <m:math><m:cn>10,000</m:cn></m:math> to produce a random
		  number between <m:math><m:cn>0</m:cn></m:math> and
		  <m:math><m:cn>10,000</m:cn></m:math>.
		</item>
		
		<item>
		  <media type="image/png" src="automatchconst.png"/>
		  Right-click the <code>y</code> terminal of the
		  <code>Multiply</code> function, select
		  <code>Create&gt;&gt;Constant</code> from the shortcut menu,
		  type <code>10000</code>, and press the
		  <code>&lt;Enter&gt;</code> key to create a numeric
		  constant.
		</item>
		
		<item>
		  <media type="image/png" src="roundnearicon.png"/>
		  Place the <code>Round To Nearest</code> function,
		  located on the <code> Functions&gt;&gt;Arithmetic &amp;
		    Comparison&gt;&gt;Express Numeric </code> palette, on the
		  block diagram. This function rounds the random number to
		  the nearest integer.
		</item>
		
		<item>
		  <media type="image/png" src="noteqicon.png"/>
		  Place the <code>Not Equal?</code> function, located on
		  the <code>Functions&gt;&gt;Arithmetic &amp;
		    Comparison&gt;&gt;Express Comparison</code> palette, on the
		  block diagram. This function compares the random number
		  with <code>Number to Match</code> and returns
		  <code>True</code> if the numbers are not equal;
		  otherwise, it returns <code>False</code>.
		</item>
		
		<item>
		  <media type="image/png" src="while.png"/>
		  Place the <code>While Loop</code>, located on the
		  <code>Functions&gt;&gt;All Functions&gt;&gt;Structures</code>
		  palette, on the block diagram.  Right-click the
		  conditional terminal and select <code>Continue if
		    True</code> from the shortcut menu.
		  <note>
		    Use the <code>While Loop</code> with <code>Stop</code>
		    button, located on the <code>Execution Control</code>
		    palette, when you need a stop button to stop the
		    <code>While Loop</code>.  In this exercise, you use
		    the <code>Number to Match</code> control to stop the
		    loop; you do not need a <code>Stop</code> button.
		  </note>
		</item>
		
		<item>
		  <media type="image/png" src="iteration.png"/>
		  Wire the <code>iteration</code> terminal to the border
		  of the <code>While Loop</code>.  A blue tunnel appears
		  on the <code>While Loop</code> border. You will wire the
		  tunnel to the <code>Increment</code> function. Each time
		  the loop executes, the iteration terminal increments by
		  one. The iteration count passes out of the loop upon
		  completion.  Increment this value by one outside the
		  loop because the count starts at
		  <m:math><m:cn>0</m:cn></m:math>.
		</item>
		
		<item>
		  <media type="image/png" src="incremicon.png"/>
		  Place the <code>Increment</code> function, located on
		  the <code>Functions&gt;&gt;Arithmetic &amp;
		    Comparison&gt;&gt;Express Numeric</code> palette, on the block
		  diagram. This function adds
		  <m:math><m:cn>1</m:cn></m:math> to the <code>While
		    Loop</code> count. A coercion dot appears on the <code>
		    Number of iterations </code> output to indicate that
		  LabVIEW coerced the numeric representation of the
		  iteration terminal to match the numeric representation
		  of the <code>Number of iterations</code> output. Refer
		  to the <cnxn document="m12214">For Loops</cnxn> section for
		  more information about numeric conversion.
		</item>
	      </list>
	    </item>
	    
	    <item>
	      Save the VI as <code>Auto Match.vi</code>.
	    </item>
	  </list>   
	</section>
	
	<section> 
	  <name> Run the VI </name>
	  <list id="end1" type="enumerated">
	    <item> 
	      Display the front panel and change the number in
	      <code>Number to Match</code>.
	    </item>
	    
	    <item>
	      Run the VI. Change <code>Number to Match</code> and run the
	      VI again. <code>Current Number</code> updates at every
	      iteration of the loop because it is inside the
	      loop. <code>Number of iterations</code> updates upon
	      completion because it is outside the loop.
	    </item>
	    
	    <item> 
	      <media type="image/png" src="exehilit.png"/>
	      To see how the VI updates the indicators, enable execution
	      highlighting. On the block diagram toolbar, click the
	      <code>Highlight Execution</code> button, shown at left, to
	      enable execution highlighting. Execution highlighting shows
	      the movement of data on the block diagram from one node to
	      another so you can see each number as the VI generates it.
	    </item>

	    <item> 
	      Change <code>Number to Match</code> to a number that is out
	      of the data range, which is <m:math><m:cn>0</m:cn></m:math>
	      to <m:math><m:cn>10000</m:cn></m:math> with an increment of
	      <m:math><m:cn>1</m:cn></m:math>.
	    </item> 

	    <item> 
	      Run the VI. LabVIEW coerces the out-of-range value to the
	      nearest value in the specified data range.
	    </item> 

	    <item> 
	      Close the VI.
	    </item> 
	  </list>
	</section>
      </problem>
    <solution>
      <para id="solution1">
        
  <media type="application/x-labviewrpvi80" src="AutoMatch.vi">
     <param name="width" value="600"/>
     <param name="height" value="575"/>
  </media></para>
    </solution></exercise>
  </content>
  
</document>
