<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>theMike.com</title>
	<atom:link href="http://themike.com/feed" rel="self" type="application/rss+xml" />
	<link>http://themike.com</link>
	<description></description>
	<lastBuildDate>Mon, 19 Jul 2010 18:42:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>You Can Do Stupid Stuff With VBA</title>
		<link>http://themike.com/you-can-do-stupid-stuff-with-vba</link>
		<comments>http://themike.com/you-can-do-stupid-stuff-with-vba#comments</comments>
		<pubDate>Mon, 24 May 2010 18:31:42 +0000</pubDate>
		<dc:creator>mike.hanson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[vba]]></category>

		<guid isPermaLink="false">http://www.themike.com/?p=55</guid>
		<description><![CDATA[As I graduated college I must admit being very ignorant about how much Microsoft Office is used in the business world.  For me in IT that meant supporting Office much more than I expected.  As a programmer specifically I had no idea I would be working on business tools built for Office.
I got my first [...]]]></description>
			<content:encoded><![CDATA[<p>As I graduated college I must admit being very ignorant about how much Microsoft Office is used in the business world.  For me in IT that meant supporting Office much more than I expected.  As a programmer specifically I had no idea I would be working on business tools built for Office.</p>
<p>I got my first taste of these tools during my short stint in support at my first job.  While I was there, one of my colleagues would use Excel to generate reports on systems we were maintaining.  Data was pasted into Excel and we would run some macros to massage it into useful reports.  Since the data sets were always small this was a perfect use for macros.</p>
<p><img class="alignleft size-full wp-image-57" title="Macro Flower Shot" src="http://www.themike.com/wp-content/uploads/2010/05/macro.jpg" alt="Macro Flower Shot" width="200" height="200" />When I started at my second job I was surprised to learn that some businesses actually make a living from macros.  Oh they don&#8217;t start out that way.  First some business analyst comes up with a report that is really useful.  Then that same analyst uses the &#8220;Record New Macro…&#8221; button to automate some of the report.  From there it grows too big and is transferred to IT where it is extended and modified and becomes a general monstrosity.  And after debugging a few of the horrible things I decided to learn a little more of the macro language.</p>
<p>What better way to do that than to think back to college.  Back then one of the assignments I had was to write a random walk function.  Imagine standing next to a lamppost on the street.  From the lamppost you can take a step in one of four directions; North, South, East, or West.  You take a step in a random direction and then look at where you are.  From your new location you take another step in a random direction and you keep taking these random steps for a while.  Finally you stop and look up, how far away from the lamppost are you?</p>
<p>The following function does that only much faster than you or I could.  It takes 20,000 steps total and colors them along the way.  Every 2,000 steps it will change colors leaving a cool trail as it goes along.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Public</span> <span style="color: #000080;">Sub</span> TakeAWalk()
    Workbooks(<span style="color: #800000;">&quot;theMikeCom_RandomWalk.xls&quot;</span>).Activate
    ActiveWorkbook.Worksheets(<span style="color: #800000;">&quot;Board&quot;</span>).<span style="color: #000080;">Select</span>
&nbsp;
    <span style="color: #008000;">' Where on the sheet should we start?
</span>    ActiveSheet.Range(<span style="color: #800000;">&quot;EE150&quot;</span>).<span style="color: #000080;">Select</span>
&nbsp;
    <span style="color: #008000;">' How many steps per turn should we take?
</span>    STEPS_PER_TURN = 2000
&nbsp;
    <span style="color: #008000;">' How many turns should we take?
</span>    TURNS = 10
&nbsp;
    <span style="color: #000080;">For</span> j = 3 <span style="color: #000080;">To</span> (TURNS + 3)
    <span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> STEPS_PER_TURN
&nbsp;
        <span style="color: #008000;">' Should we step east or west?
</span>        randomX = Int(4 * Rnd)
&nbsp;
        <span style="color: #008000;">' Should we step north or south?
</span>        randomY = Int(4 * Rnd)
&nbsp;
        <span style="color: #008000;">' Move west-east
</span>        <span style="color: #000080;">Select</span> <span style="color: #000080;">Case</span> randomX
            <span style="color: #000080;">Case</span> 2 <span style="color: #008000;">' Move one step west
</span>                <span style="color: #000080;">If</span> ActiveCell.Column &lt; 1 <span style="color: #000080;">Then</span> <span style="color: #008000;">' Do not overstep the west border
</span>                    ActiveCell.Offset(0, -1).<span style="color: #000080;">Select</span>
                <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
            <span style="color: #008000;">' Case 1 - Stay in the same spot
</span>
            <span style="color: #000080;">Case</span> 0 <span style="color: #008000;">' Move one step east
</span>                <span style="color: #000080;">If</span> ActiveCell.Column &lt;= 255 <span style="color: #000080;">Then</span> <span style="color: #008000;">' Do not overstep the east border                     ActiveCell.Offset(0, 1).Select                 End If         End Select         ' Move north-south         Select Case randomY             Case 2 ' Move one step north                 If ActiveCell.Row &amp;gt; 1 Then ' Do not overstep the north border
</span>                    ActiveCell.Offset(-1, 0).<span style="color: #000080;">Select</span>
                <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
            <span style="color: #008000;">' Case 1 - Stay in the same spot
</span>
            <span style="color: #000080;">Case</span> 0 <span style="color: #008000;">' Move one step south
</span>                <span style="color: #000080;">If</span> ActiveCell.Row &amp;lt;= 65535 <span style="color: #000080;">Then</span> <span style="color: #008000;">' Do not overstep the south border
</span>                    ActiveCell.Offset(1, 0).<span style="color: #000080;">Select</span>
                <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
        <span style="color: #000080;">End</span> <span style="color: #000080;">Select</span>
&nbsp;
        <span style="color: #008000;">' Leave a trail
</span>        ActiveCell.Interior.ColorIndex = j
&nbsp;
    <span style="color: #000080;">Next</span> i
    <span style="color: #000080;">Next</span> j
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p>With that done I came up with a bonus stupid trick, the square flower.  This function will generate a square of random size with each section of the square filled with a different color.  This function taught me some tricks about looping in VBA, some ways are a lot faster than others.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Public</span> <span style="color: #000080;">Sub</span> Flower()
    Workbooks(<span style="color: #800000;">&quot;theMikeCom_RandomWalk.xls&quot;</span>).Activate
    ActiveWorkbook.Worksheets(<span style="color: #800000;">&quot;Board&quot;</span>).<span style="color: #000080;">Select</span>
&nbsp;
    <span style="color: #000080;">Dim</span> start <span style="color: #000080;">As</span> Range
    <span style="color: #000080;">Dim</span> Length <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
    <span style="color: #000080;">Dim</span> Width <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
    <span style="color: #000080;">Dim</span> Color <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
&nbsp;
    <span style="color: #008000;">' The starting point of the flower
</span>    <span style="color: #000080;">Set</span> start = ActiveCell
&nbsp;
    <span style="color: #008000;">' The maximum size of the flower
</span>    size = Int(57 * Rnd)
&nbsp;
    <span style="color: #008000;">' Ignore boundry errors for now
</span>    <span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">Resume</span> <span style="color: #000080;">Next</span>
&nbsp;
    <span style="color: #000080;">For</span> z = 0 <span style="color: #000080;">To</span> size
        <span style="color: #008000;">' Generate a random color for this row
</span>        Color = Int((56 - 1 + 1) * Rnd + 1)
&nbsp;
        <span style="color: #008000;">' Left side
</span>        Range(start.Offset(0, 0), start.Offset(Length, 0)).Interior.ColorIndex = Color
&nbsp;
        <span style="color: #008000;">' Bottom side
</span>        Range(start.Offset(Length, 0), start.Offset(Length, Length)).Interior.ColorIndex = Color
&nbsp;
        <span style="color: #008000;">' Upper side
</span>        Range(start.Offset(0, 0), start.Offset(0, Width)).Interior.ColorIndex = Color
&nbsp;
        <span style="color: #008000;">' Right side
</span>        Range(start.Offset(0, Width), start.Offset(Width, Width)).Interior.ColorIndex = Color
&nbsp;
        <span style="color: #000080;">Set</span> start = start.Offset(-1, -1)
        Length = Length + 2
        Width = Width + 2
    <span style="color: #000080;">Next</span> z
&nbsp;
    <span style="color: #000080;">On</span> <span style="color: #000080;">Error</span> <span style="color: #000080;">GoTo</span> 0
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p>So what did I learn after all of this?  For one I have a strong dislike for VBA.  It works well for small projects with small data sets.  However business managers like to take those small projects and expand on them.  You are better off doing it right the first time instead of maintaining a large clunky macro.  <img class="size-full  wp-image-56 alignright" title="Excel Random Walk" src="http://www.themike.com/wp-content/uploads/2010/05/excel.jpg" alt="Excel Random Walk" width="300" height="212" /></p>
<p><a href="http://www.themike.com/wp-content/uploads/2010/05/theMikeCom_RandomWalk.xls">Download the complete macro here.</a> You will need to enable macros in your security settings to get them to work.  Once enabled, select &#8220;Random Walk&#8221; from the &#8220;theMike.com &#8211; Stupid Tricks&#8221; menu.  This will start a random walk which will finish after a couple of seconds.  The &#8220;Square Flower&#8221; menu item will create a square flower under your cursor.</p>
<p>Ok, now I&#8217;m going to go and forget I know anything about VBA.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;">
<p><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --><!--[if gte mso 10]> <mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --> <!--[endif]--></p>
<p class="MsoNormal">As I graduated college I must admit being very ignorant about how Microsoft Office is used in the business world. <span> </span>For me in IT that meant supporting Office much more than I expected.<span> </span>As a programmer specifically I had no idea I would be working on business tools built for Office.</p>
<p class="MsoNormal">
<p class="MsoNormal">I got my first taste of these tools during my short stint in support at HP.<span> </span>While I was there one of my colleagues would use Excel to generate reports on systems we were maintaining.<span> </span>Data was pasted into Excel and we would run some macros to massage it into useful reports.<span> </span>Since the data sets were always small this was a perfect use for macros.</p>
<p class="MsoNormal">
<p class="MsoNormal">When I started at LECG I was surprised to learn that some businesses actually make a living from macros.<span> </span>Oh they don&#8217;t start out that way.<span> </span>First some business analyst comes up with a report that is really useful.<span> </span>Then that same analyst uses the &#8220;Record New Macro…&#8221; button to automate some of the report.<span> </span>From there it grows too big and is transferred to IT where it is extended and modified and becomes a general monstrosity.<span> </span>And after debugging a few of the horrible things I decided to learn a little more of the macro language.<span> </span></p>
<p class="MsoNormal">
<p class="MsoNormal">What better way to do that than to think back to college.<span> </span>Back then one of the assignments I had was to write a random walk function.<span> </span>Imagine standing next to a lamppost on the street.<span> </span>From the lamppost you can take a step in one of four directions; North, South, East, or West.<span> </span>You take a step in a random direction and then look at where you are.<span> </span>From your new location you take another step in a random direction and you keep taking these random steps for a while.<span> </span>Finally you stop and look up, how far away from the lamppost are you?</p>
<p class="MsoNormal">
<p class="MsoNormal">The following function does that only much faster than you or I could.<span> </span>It takes 20,000 steps total and colors them along the way.<span> </span>Every 2,000 steps it will change colors leaving a cool trail as it goes along.</p>
<p class="MsoNormal">
<p class="MsoNormal">[code]Public Sub TakeAWalk()</p>
<p class="MsoNormal"><span> </span>Workbooks("theMikeCom_RandomWalk.xls").Activate</p>
<p class="MsoNormal"><span> </span>ActiveWorkbook.Worksheets("Board").Select</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' Where on the sheet should we start?</p>
<p class="MsoNormal"><span> </span>ActiveSheet.Range("EE150").Select</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' How many steps per turn should we take?</p>
<p class="MsoNormal"><span> </span>STEPS_PER_TURN = 2000</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' How many turns should we take?</p>
<p class="MsoNormal"><span> </span>TURNS = 10</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>For j = 3 To (TURNS + 3)</p>
<p class="MsoNormal"><span> </span>For i = 0 To STEPS_PER_TURN</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' Should we step east or west?</p>
<p class="MsoNormal"><span> </span>randomX = Int(4 * Rnd)</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' Should we step north or south?</p>
<p class="MsoNormal"><span> </span>randomY = Int(4 * Rnd)</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' Move west-east</p>
<p class="MsoNormal"><span> </span>Select Case randomX</p>
<p class="MsoNormal"><span> </span>Case 2 ' Move one step west</p>
<p class="MsoNormal"><span> </span>If ActiveCell.Column &gt; 1 Then ' Do not overstep the west border</p>
<p class="MsoNormal"><span> </span>ActiveCell.Offset(0, -1).Select</p>
<p class="MsoNormal"><span> </span>End If</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' Case 1 - Stay in the same spot</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>Case 0 ' Move one step east</p>
<p class="MsoNormal"><span> </span>If ActiveCell.Column &lt;= 255 Then ' Do not overstep the east border</p>
<p class="MsoNormal"><span> </span>ActiveCell.Offset(0, 1).Select</p>
<p class="MsoNormal"><span> </span>End If</p>
<p class="MsoNormal"><span> </span>End Select</p>
<p class="MsoNormal">
<p class="MsoNormal"><span> </span>' Move north-south</p>
<p class="MsoNormal"><span> </span>Select Case randomY</p>
<p class="MsoNormal"><span> </span>Case 2 ' Move one step north</p>
<p class="MsoNormal"><span> </span>If ActiveCell.Row &gt; 1 Then ' Do not overstep the north border</p>
<p class="MsoNormal"><span> </span>ActiveCell.Offset(-1, 0).Select</p>
<p class="MsoNormal"><span> </span>End If</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' Case 1 - Stay in the same spot</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span><span> </span>Case 0 ' Move one step south</p>
<p class="MsoNormal"><span> </span>If ActiveCell.Row &lt;= 65535 Then ' Do not overstep the south border</p>
<p class="MsoNormal"><span> </span>ActiveCell.Offset(1, 0).Select</p>
<p class="MsoNormal"><span> </span>End If</p>
<p class="MsoNormal"><span> </span>End Select</p>
<p class="MsoNormal">
<p class="MsoNormal"><span> </span>' Leave a trail</p>
<p class="MsoNormal"><span> </span>ActiveCell.Interior.ColorIndex = j</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>Next i</p>
<p class="MsoNormal"><span> </span>Next j</p>
<p class="MsoNormal">End Sub[/code]</p>
<p class="MsoNormal">
<p class="MsoNormal">With that done I came up with a bonus stupid trick, the square flower.<span> </span>This function will generate a square of random size with each section of the square filled with a different color.<span> </span>This function taught me some tricks about looping in VBA, some ways are a lot faster than others.</p>
<p class="MsoNormal">
<p class="MsoNormal">[code] Public Sub Flower()</p>
<p class="MsoNormal"><span> </span>Workbooks("theMikeCom_RandomWalk.xls").Activate</p>
<p class="MsoNormal"><span> </span>ActiveWorkbook.Worksheets("Board").Select</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>Dim start As Range</p>
<p class="MsoNormal"><span> </span>Dim Length As Integer</p>
<p class="MsoNormal"><span> </span>Dim Width As Integer</p>
<p class="MsoNormal"><span> </span>Dim Color As Integer</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' The starting point of the flower</p>
<p class="MsoNormal"><span> </span>Set start = ActiveCell</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' The maximum size of the flower</p>
<p class="MsoNormal"><span> </span>size = Int(57 * Rnd)</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' Ignore boundry errors for now</p>
<p class="MsoNormal"><span> </span>On Error Resume Next</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>For z = 0 To size</p>
<p class="MsoNormal"><span> </span>' Generate a random color for this row</p>
<p class="MsoNormal"><span> </span>Color = Int((56 - 1 + 1) * Rnd + 1)</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' Left side</p>
<p class="MsoNormal"><span> </span>Range(start.Offset(0, 0), start.Offset(Length, 0)).Interior.ColorIndex = Color</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' Bottom side</p>
<p class="MsoNormal"><span> </span>Range(start.Offset(Length, 0), start.Offset(Length, Length)).Interior.ColorIndex = Color</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' Upper side</p>
<p class="MsoNormal"><span> </span>Range(start.Offset(0, 0), start.Offset(0, Width)).Interior.ColorIndex = Color</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>' Right side</p>
<p class="MsoNormal"><span> </span>Range(start.Offset(0, Width), start.Offset(Width, Width)).Interior.ColorIndex = Color</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>Set start = start.Offset(-1, -1)</p>
<p class="MsoNormal"><span> </span>Length = Length + 2</p>
<p class="MsoNormal"><span> </span>Width = Width + 2</p>
<p class="MsoNormal"><span> </span>Next z</p>
<p class="MsoNormal"><span> </span></p>
<p class="MsoNormal"><span> </span>On Error GoTo 0</p>
<p class="MsoNormal">End Sub[/code]</p>
<p class="MsoNormal">
<p class="MsoNormal">So what did I learn after all of this?<span> </span>For one I have a strong dislike for VBA.<span> </span>It works well for small projects with small data sets.<span> </span>However business managers like to take those small projects and expand on them.<span> </span>You are better off doing it right the first time instead of maintaining a large clunky macro.<span> </span></p>
<p class="MsoNormal">
<p class="MsoNormal">Download the complete macro here.<span> </span>You will need to enable macros in your security settings to get them to work.<span> </span>Once enabled, select &#8220;Random Walk&#8221; from the &#8220;theMike.com &#8211; Stupid Tricks&#8221; menu.<span> </span>This will start a random walk which will finish after a couple of seconds.<span> </span>The &#8220;Square Flower&#8221; menu item will create a square flower under your cursor.</p>
<p class="MsoNormal">
<p class="MsoNormal">Ok, now I&#8217;m going to go and forget I know anything about VBA.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://themike.com/you-can-do-stupid-stuff-with-vba/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an Audiobook for the iPod</title>
		<link>http://themike.com/create-an-audiobook</link>
		<comments>http://themike.com/create-an-audiobook#comments</comments>
		<pubDate>Mon, 17 May 2010 05:29:05 +0000</pubDate>
		<dc:creator>mike.hanson</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[audiobook]]></category>

		<guid isPermaLink="false">http://www.themike.com/?p=22</guid>
		<description><![CDATA[Ahh programming for a living&#8230;  Most days it&#8217;s easy get into a rhythm and looking up for the first time find that it&#8217;s already time to go.  But every so often there are those days that just won&#8217;t quit.  On those long days I find it&#8217;s best to plug in my iPod and get cranking [...]]]></description>
			<content:encoded><![CDATA[<p>Ahh programming for a living&#8230;  Most days it&#8217;s easy get into a rhythm and looking up for the first time find that it&#8217;s already time to go.  But every so often there are those days that just won&#8217;t quit.  On those long days I find it&#8217;s best to plug in my iPod and get cranking on a problem.  A little background noise can do wonders and lately I have been on an audiobook kick.</p>
<p><img class="size-full wp-image-43 alignright" title="An Audiobook on the iPod" src="http://www.themike.com/wp-content/uploads/2010/05/cvipod.jpg" alt="iPod" width="200" height="150" /></p>
<p>iPods treat audiobooks and podcasts differently than they do music files.  For one you can leave a podcast, listen to something else, and later pick up where you left off.  An iPod won&#8217;t do this when you are listening to music.  Furthermore an audiobook can have chapter markings making it easier to find a chapter in a longer book.</p>
<p>iTunes makes it easy to create a music file for the iPod.  You can insert a CD and iTunes will import it at the push of a button.  Creating a proper audiobook however, is impossible with iTunes.  Oh sure you could import a whole CD as a single file but what if your audiobook covers multiple CDs?</p>
<p>I&#8217;ve had this problem for a while now.  My initial solution involved importing each track and numbering them in a way that they would line up in a playlist.  This works, but it&#8217;s annoying.  I can play the book but if I stop I have to remember which chapter I left off with.  If I don&#8217;t go back to the book for a couple of days I forget where I am and have to start over.  A couple of weeks ago I finally had enough and went searching for a better solution.</p>
<p>The solution to my problem came from a program called <em>Chapter and Verse</em> by <a href="http://lodensoftware.com/chapter-and-verse/">lodensoftware.com</a>.  The program will take a list of AAC (.m4a) files and convert them into one single audiobook (.m4b).  This makes creating an audiobook from a CD very easy.  Simply import the CD using iTunes in the AAC format and then use <em>Chapter and Verse</em> to make the conversion.</p>
<p><img class="size-medium wp-image-44  alignleft" title="Chapter and Verse  - Main  screen" src="http://www.themike.com/wp-content/uploads/2010/05/cvmain-e1274246318237.jpg" alt="Chapter and Verse - Main screen" width="300" height="260" /></p>
<p style="text-align: left;"><em>Chapter and Verse</em> is not perfect however.  If files are not in the AAC format it will have to convert them into this format before creating the audiobook.  If you use a free audiobook solution such as <a href="http://librivox.org/">librivox.org</a> this means it&#8217;ll have to convert each file before combining them into one.  Not too big of a deal, just plan a little extra time when creating an audiobook from a set of mp3s.</p>
<p style="text-align: left;">Creating an audiobook is very easy in <em>Chapter and Verse</em>.  First <a href="http://lodensoftware.com/downloads/">download</a> and install the application.  Then fire it up and follow the instructions below.</p>
<ol>
<li>When <em>Chapter and Verse</em> loads it opens to an empty project.  Each project will contain all of the chapters in each audiobook you create.</li>
<li>Each file you import becomes a new chapter in your audiobook.  Click the &#8220;Add Files&#8221; button to begin adding audio files to your audiobook.  The open file dialog only shows MP4 files by default so be sure to change the filter if you are adding say .mp3 files.</li>
<li>If you added a file that is not in the AAC format <em>Chapter and Verse</em> will attempt to convert the file using iTunes.  In that case click &#8220;Yes &#8211; Convert&#8221; on the conversion screen.  iTunes will open for the converstion, do not close it until it&#8217;s done.  When Chapter and Verse is done with the conversion your files will be added to the &#8220;Input Files&#8221; tab.</li>
<li>Whenever a new chapter is added <em>Chapter and Verse</em> will first validate the files, then generate some chapter data, and finally merge in your tracks.  If you have a lot of files to add this can become a little annoying.  To turn it off briefly click the &#8220;Autobuild On&#8221; button to change it to &#8220;Autobuild Off&#8221;.</li>
<li>Click on the &#8220;Chapters&#8221; tab to change the chapter name.  For most of my audiobooks I like to choose the &lt;Filename #&gt; option.</li>
<li>Click on the &#8220;Metadata&#8221; tab and change the file information if you would like.</li>
<li>Finally make sure &#8220;Autobuild&#8221; is on and then click the &#8220;Build Audiobook&#8221; button.  Chapter and Verse will ask you where to save the file and then will create the book.</li>
</ol>
<p>That&#8217;s pretty much as easy as it gets!</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;">
<p>Ahh programming for a living&#8230;  There&#8217;s nothing quite like working on someone else&#8217;s problem for hours on end trying to get the dumb thing to do what you want.</p>
<p>Alright I&#8217;ll admit it; there are some days when I would rather be at home working on one of my own projects.  Those days I find it very hard to focus because one thought runs through my head.  &#8220;My own projects are fun and exciting and this is soooo BORING, I want to go home!&#8221;</p>
<p>But since my fun projects don&#8217;t put food on the table I have to snap out of it and get my head back into what actually does.  I find on those days it&#8217;s best to medicate the problem a little with my trusty iPod.  With my iPod I can do something for myself while still working and lately I have been on an audiobook and podcast kick.</p>
<p>iPods treat audiobooks and podcasts differently than they do music files.  For one you can leave a podcast, listen to something else, and later pick up where you left off.  An iPod won&#8217;t do this when you are listening to music.  Furthermore an audiobook can have chapter markings making it easier to find a chapter in a longer book.</p>
<p>iTunes makes it easy to create a music file for the iPod.  You can insert a CD and iTunes will import it at the push of a button.  Creating a proper audiobook however, is impossible with iTunes.  Oh sure you could import a whole CD as a single file but what if your audiobook covers multiple CDs?</p>
<p>I&#8217;ve had this problem for a while now.  My initial solution involved importing each track and numbering them in a way that they would line up in a playlist.  This works, but it&#8217;s annoying.  I can play the book but if I stop I have to remember which chapter I left off with.  If I don&#8217;t go back to the book for a couple of days I forget where I am and have to start over.  A couple of weeks ago I finally had enough and went searching for a better solution.</p>
<p>The solution to my problem came from a program called Chapter and Verse by lodensoftware.com.  The program will take a list of AAC (.m4a) files and convert them into one single audiobook (.m4b).  This makes creating an audiobook from a CD very easy.  Simply import the CD using iTunes in the AAC format and then use Chapter and Verse to make the conversion.</p>
<p>Chapter and Verse is not perfect however.  If files are not in the AAC format it will have to convert them into this format before creating the audiobook.  If you use a free audiobook solution such as librivox.org this means it&#8217;ll have to convert each file before combining them into one.  Not too big of a deal, just plan a little extra time when creating an audiobook from a set of mp3s.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://themike.com/create-an-audiobook/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Starting that Windows Forms .NET Application</title>
		<link>http://themike.com/starting-that-windows-forms-net-application</link>
		<comments>http://themike.com/starting-that-windows-forms-net-application#comments</comments>
		<pubDate>Sat, 10 Apr 2010 20:53:14 +0000</pubDate>
		<dc:creator>mike.hanson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.themike.com/?p=8</guid>
		<description><![CDATA[One of the pleasures that I look forward to are those &#8220;Duh&#8221; moments.  Those moments signal that I am still learning new things and therefore not falling behind the ever moving technology curve.  Not yet at least.
This week at work I have been redesigning the flow of our internal application.  When Sally gets into work [...]]]></description>
			<content:encoded><![CDATA[<p>One of the pleasures that I look forward to are those &#8220;Duh&#8221; moments.  Those moments signal that I am still learning new things and therefore not falling behind the ever moving technology curve.  Not yet at least.</p>
<p>This week at work I have been redesigning the flow of our internal application.  When Sally gets into work on Monday, after a long weekend of partying, the first thing she does is launch this internal application.  It then opens a login form which disappears when she enters her credentials.  Immediately, a secondary screen shows up asking which set of data she would like to work with.  She chooses what she&#8217;s been assigned to work on and waits for the data to load in a third screen.</p>
<p>The code required to launch such an application is very straight forward.  The login form needs to be displayed and when it is dismissed the secondary form can be shown.  The third screen can be launched off of the second and will stay alive as long as the second is open.</p>
<p>Program.cs</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">///</span>
<span style="color: #008080; font-style: italic;">/// Entry point for the test application</span>
<span style="color: #008080; font-style: italic;">///</span>
<span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> Program
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #008080; font-style: italic;">/// The main entry point for the application.</span>
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #000000;">&#91;</span>STAThread<span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        Application.<span style="color: #0000FF;">EnableVisualStyles</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        Application.<span style="color: #0000FF;">SetCompatibleTextRenderingDefault</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Ask the user to login</span>
        Login.<span style="color: #0000FF;">LoginScreen</span> login <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Login.<span style="color: #0000FF;">LoginScreen</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        Application.<span style="color: #0000FF;">Run</span><span style="color: #000000;">&#40;</span>login<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>login.<span style="color: #0000FF;">DialogResult</span> <span style="color: #008000;">==</span> DialogResult.<span style="color: #0000FF;">OK</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Run the main application</span>
            Application.<span style="color: #0000FF;">Run</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> NewWindowApp.<span style="color: #0000FF;">EntryPoint</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Context</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Take a look at lines 17 and 22 in the code sample from Program.cs.  The calls to Application.Run(Form) start a message loop on the current thread enabling the form to receive Windows messages.  Application.Run(Form) essentially says to Windows, &#8220;Here take this form and show it to the user.&#8221;  The form that is supplied can launch other child forms but when it dies so does the whole application.</p>
<p>My goal this week has been to make Sally&#8217;s job a little easier by removing the secondary screen and building its functionality into the third screen.  Now normally this would be as simple as replacing line ten with Application.Run(new ThirdForm());.  However that will not work in this case because the third form has a very useful &#8220;New Window&#8221; button.</p>
<p>Oh, it will work just fine for a while.  Sally can click the button leaving her with two views of the application.  However the message loop is only hooked up to the first form and if it is closed both forms will die off.</p>
<p>I wracked by brain for a while trying to work my way around this limitation.  I could create an invisible secondary form and then fired the third from that.  But that feels like a kludge and I hate kludges.  Nothing I could think of was an optimal solution and this simple task become very frustrating.</p>
<p>It seems that the deeper the frustration the larger the slap to the forehead when the &#8220;Duh&#8221; moment hits.  The solution to my problem is in an overload to the Application.Run method that takes an ApplicationContext property.  In fact the documentation at MSDN (http://msdn.microsoft.com/en-us/library/ms157901.aspx) shows a partial solution to my problem.</p>
<p>Instead of supplying Windows with a Form to display to the user I now supply a custom ApplicationContext object.  This custom context can manage the new window call and keep the application alive no mater which form is closed.</p>
<p>Context.cs</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">///</span>
<span style="color: #008080; font-style: italic;">/// Does the work of firing off new application windows.</span>
<span style="color: #008080; font-style: italic;">///</span>
<span style="color: #0600FF;">internal</span> <span style="color: #FF0000;">class</span> Context <span style="color: #008000;">:</span> ApplicationContext
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// The number of windows currently open</span>
    <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">int</span> mWindowCount<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #008080; font-style: italic;">/// Initializes a new instance of the  class.</span>
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #0600FF;">public</span> Context<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">NewWindow</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #008080; font-style: italic;">/// Creates and shows a new window.</span>
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> NewWindow<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        NewWindow window <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NewWindow<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        window.<span style="color: #0000FF;">FormClosed</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> FormClosedEventHandler<span style="color: #000000;">&#40;</span>window_FormClosed<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008000;">++</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">mWindowCount</span><span style="color: #008000;">;</span>
&nbsp;
        window.<span style="color: #0000FF;">Show</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Close out the application when all windows have been exited</span>
    <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> window_FormClosed<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, FormClosedEventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008000;">--</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">mWindowCount</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">mWindowCount</span> <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;=</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">ExitThread</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It&#8217;s important to note that this object knows how many windows there are.  Also note that as each window is created by NewWindow() a listener is added to the FormClosed event.  These two elements allow the context to know when the last form is closed and therefore when to finally exit.</p>
<p>There you have it, a simple solution to a simple problem.   Though, most of the simple problems are bound to cause most of those &#8220;Duh&#8221; moments.</p>
<p><a href="http://www.themike.com/wp-content/uploads/2010/04/NewWindowApp.zip">Full source code for example project.</a></p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 1022px; width: 1px; height: 1px; overflow: hidden;">
<p><!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!--  /* Font Definitions */  @font-face 	{font-family:ProggyTiny; 	panose-1:0 0 0 0 0 0 0 0 0 0; 	mso-font-charset:0; 	mso-generic-font-family:auto; 	mso-font-format:other; 	mso-font-pitch:fixed; 	mso-font-signature:3 0 0 0 1 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --><!--[if gte mso 10]> <mce:style><!   /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} --> <!--[endif]--></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny; color: gray;">///</span><span style="font-family: ProggyTiny; color: green;"> </span><span style="font-family: ProggyTiny; color: gray;">&lt;summary&gt;</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny; color: gray;">///</span><span style="font-family: ProggyTiny; color: green;"> Does the work of firing off new application windows.</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny; color: gray;">///</span><span style="font-family: ProggyTiny; color: green;"> </span><span style="font-family: ProggyTiny; color: gray;">&lt;/summary&gt;</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny; color: blue;">internal</span><span style="font-family: ProggyTiny;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Context</span> : <span style="color: #2b91af;">ApplicationContext</span></span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;">{</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: green;">// The number of windows currently open</span></span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: blue;">private</span> <span style="color: blue;">int</span> mWindowCount;</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"> </span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: gray;">///</span><span style="color: green;"> Initializes a new instance of the </span><span style="color: gray;">&lt;see cref=&#8221;Context&#8221;/&gt;</span><span style="color: green;"> class.</span></span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: blue;">public</span> Context()</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: blue;">this</span>.NewWindow();</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"> </span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: gray;">///</span><span style="color: green;"> Creates and shows a new window.</span></span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: blue;">public</span> <span style="color: blue;">void</span> NewWindow()</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: #2b91af;">NewWindow</span> window = <span style="color: blue;">new</span> <span style="color: #2b91af;">NewWindow</span>(<span style="color: blue;">this</span>);</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"> </span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span>window.FormClosed += <span style="color: blue;">new</span> <span style="color: #2b91af;">FormClosedEventHandler</span>(window_FormClosed);</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"> </span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span>++<span style="color: blue;">this</span>.mWindowCount;</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"> </span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span>window.Show();</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"> </span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: green;">// Close out the application when all windows have been exited</span></span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: blue;">private</span> <span style="color: blue;">void</span> window_FormClosed(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">FormClosedEventArgs</span> e)</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span>&#8211;<span style="color: blue;">this</span>.mWindowCount;</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"> </span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: blue;">if</span> (<span style="color: blue;">this</span>.mWindowCount &lt;= 0)</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span>{</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span><span style="color: blue;">this</span>.ExitThread();</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;"><span> </span>}</span></p>
<p class="MsoNormal"><span style="font-family: ProggyTiny;">}</span></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://themike.com/starting-that-windows-forms-net-application/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
