<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>OfficePalooza</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/officepalooza/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/officepalooza/feed.xml</link>
    <description>OfficePalooza is an online competition that tests your skills in Visual Basic for Applications, teaches you new skills, and above all, ensures that you have some fun with it.</description>
    <lastBuildDate>Wed, 17 Apr 2019 04:05:35 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Prize Update</title>
      <link>https://docs.microsoft.com/archive/blogs/officepalooza/prize-update</link>
      <pubDate>Wed, 24 Jun 2009 11:48:00 GMT</pubDate>
      <dc:creator><![CDATA[Greg Stemp]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/officepalooza/2009/06/24/prize-update/</guid>
      <description><![CDATA[All the prize winners have been notified and the prizes have been mailed out. If you were notified...]]></description>
      <content:encoded><![CDATA[<P>All the prize winners have been notified and the prizes have been mailed out. If you were notified as a winner and got back to us with your mailing address you should be receiving your prize any day now (if you haven't already). If you sent us your info but haven't received your prize by July 1, 2009, let us know.</P>
<P>Thanks again to everyone who participated!</P>
<P>Sincerely,</P>
<P>Binder Clippy (and the OfficePalooza Team)</P>]]></content:encoded>
    </item>
    <item>
      <title>The End</title>
      <link>https://docs.microsoft.com/archive/blogs/officepalooza/the-end</link>
      <pubDate>Sun, 03 May 2009 23:30:00 GMT</pubDate>
      <dc:creator><![CDATA[Greg Stemp]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/officepalooza/2009/05/03/the-end/</guid>
      <description><![CDATA[OfficePalooza is over, but you can still find all the challenges and solutions from the Home page,...]]></description>
      <content:encoded><![CDATA[<FONT face=Calibri>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT size=3>OfficePalooza is over, but you can still find all the challenges and solutions from the </FONT><A href="https://blogs.msdn.com/officepalooza/pages/9556066.aspx"><B style="mso-bidi-font-weight: normal"><FONT size=3>Home page</FONT></B></A><FONT size=3>, as well as links to all sorts of great information about various Microsoft Office products.</FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT size=3>And be sure to go </FONT><A href="https://go.microsoft.com/fwlink/?LinkId=148922"><B style="mso-bidi-font-weight: normal"><FONT size=3>Solutions for Advanced Business Users of Office</FONT></B></A><FONT size=3>, a special feature available for a short time only!</FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT size=3>Thanks again to everyone who joined us!</FONT></FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Day 10</title>
      <link>https://docs.microsoft.com/archive/blogs/officepalooza/day-10</link>
      <pubDate>Fri, 01 May 2009 11:02:00 GMT</pubDate>
      <dc:creator><![CDATA[Greg Stemp]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/officepalooza/2009/05/01/day-10/</guid>
      <description><![CDATA[Well, this is it. Day 10. The final day of our two-week super-event, OfficePalooza. We’ll continue...]]></description>
      <content:encoded><![CDATA[<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT face=Calibri size=3>Well, this is it. Day 10. The final day of our two-week super-event, OfficePalooza. We’ll continue updating scores until we’ve scored all the entries. We’ll start notifying prize winners soon. Be sure to visit the </FONT><A href="https://blogs.msdn.com/officepalooza/pages/9556066.aspx"><B style="mso-bidi-font-weight: normal"><FONT face=Calibri size=3>Home page</FONT></B></A><FONT face=Calibri size=3> for links to all the challenges, solutions, and scores.</FONT></P><SPAN style="FONT-SIZE: 11pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA">Thank you to everyone who joined us! We had a lot of fun and we hope you did too. Before you go, look at what we have for our final day: <A href="https://blogs.msdn.com/officepalooza/pages/9556066.aspx"><B style="mso-bidi-font-weight: normal">Microsoft Office Outlook Day</B></A>.</SPAN>]]></content:encoded>
    </item>
    <item>
      <title>Solution - Novice Challenge 10: Skip It</title>
      <link>https://docs.microsoft.com/archive/blogs/officepalooza/solution-novice-challenge-10-skip-it</link>
      <pubDate>Fri, 01 May 2009 00:43:00 GMT</pubDate>
      <dc:creator><![CDATA[Greg Stemp]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/officepalooza/2009/05/01/solution-novice-challenge-10-skip-it/</guid>
      <description><![CDATA[Did you like the first slide in this challenge? We hope so. The first slide turned out...]]></description>
      <content:encoded><![CDATA[<META content="Microsoft Word 12 (filtered)" name=Generator>
<STYLE>
<!--
 /* Font Definitions */
 @font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:0in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
	{mso-style-link:"Balloon Text Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:8.0pt;
	font-family:"Tahoma","sans-serif";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:.5in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:.5in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
span.BalloonTextChar
	{mso-style-name:"Balloon Text Char";
	mso-style-link:"Balloon Text";
	font-family:"Tahoma","sans-serif";}
.MsoPapDefault
	{margin-bottom:10.0pt;
	line-height:115%;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 ol
	{margin-bottom:0in;}
ul
	{margin-bottom:0in;}
-->
</STYLE>

<DIV class=Section1>
<P class=MsoNormal>Did you like the first slide in this challenge? We hope so. The first slide turned out to where Binder Clippy has been hiding throughout OfficePalooza. We wanted to give Binder Clippy a little bigger role throughout this competition, but, well, there were some contract issues…. As a result, Binder Clippy got demoted from emcee to featured character on a PowerPoint slide.</P>
<P class=MsoNormal><B>Note</B>. If you don’t know what we’re talking about, don’t worry about it. We were going to add a link to the <I>real</I> story of Binder Clippy, but someone snuck in and rewrote the tale before we got to it. To be honest, we’re now too embarrassed by the final outcome to show it to you. But trust us, it was a great story.</P>
<P class=MsoNormal>Really.</P>
<P class=MsoNormal>But enough about our poor, ill-fated mascot; it’s time to talk about this challenge. This was a tough one. As you probably found out, it’s one thing to start up a slide show from a macro, but it’s a whole ‘nother thing to show the slides in any order other than the order they appear in PowerPoint. But we managed, by doing this:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Public Sub SkipSlides()</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim i As Integer</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim j As Integer</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim o As Integer</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim e As Integer</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim temp1 As Integer</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim temp2 As Integer</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim strShowName As String</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim arrOdd() As Integer</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim arrEven() As Integer</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim slideCount As Integer</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim arrAll() As Integer</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim customShow As NamedSlideShow</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Find out how many slides are in the slideshow.</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">slideCount = ActivePresentation.Slides.Count</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Initialize variables</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">i = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">strShowName = "Alternate Slides"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">temp1 = slideCount / 2 'Divide the slide count by 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">temp2 = slideCount Mod 2 'If there is an odd number of slides, need to account for the odd one</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Number of odd-numbered slides (slides 1, 3, etc.) is temp1 plus temp2;</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">' number of even-numbered slides (slides 2, 4, etc.) is half of the total.</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">o = temp1 + temp2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">e = temp1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">ReDim arrOdd(o)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">ReDim arrEven(e)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">ReDim arrAll(slideCount)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Create an array containing the slide ID of each odd-numbered slide.</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">j = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">While (i &lt;= o)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; arrOdd(i) = ActivePresentation.Slides(j).SlideID</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; j = j + 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; i = i + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Wend</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Create an array containing the slide ID of each even-numbered slide.</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">j = 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">i = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">While (i &lt;= e)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; arrEven(i) = ActivePresentation.Slides(j).SlideID</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; j = j + 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; i = i + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Wend</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Add the odd-numbered slides to a single array.</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">i = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">j = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">While (i &lt;= o)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; arrAll(i) = arrOdd(i)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; i = i + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Wend</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Add the even-numbered slides to the array following the odd-numbered slides.</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">While (j &lt;= e)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; arrAll(i) = arrEven(j)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j = j + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; i = i + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Wend</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Set each slide to transition after 2 seconds.</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">i = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">While (i &lt;= slideCount)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; With ActivePresentation.Slides(i).SlideShowTransition</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .AdvanceOnTime = msoCTrue</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .AdvanceTime = 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; End With</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; i = i + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Wend</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Create a custom slide show from the array of odd and even slides.</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">ActivePresentation.SlideShowSettings.NamedSlideShows.Add strShowName, arrAll</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Start the slide show</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">With ActivePresentation.SlideShowSettings</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .RangeType = ppShowNamedSlideShow</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .SlideShowName = strShowName</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .Run</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">End With</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Delete the custom slide show</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">For Each customShow In ActivePresentation.SlideShowSettings.NamedSlideShows</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; customShow.Delete</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Next customShow</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">End Sub</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>As usual, we start out by declaring a bunch of variables that will be used throughout our code. We then have this line of code:</P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">slideCount = ActivePresentation.Slides.Count</SPAN></P>
<P class=MsoNormal>All we’re doing here is using the <B>Count</B> property to find out how many slides are in the presentation, then storing that value in the variable slideCount. You’ll see how we use that in a moment. But first let’s look at a couple of variables we need to initialize:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">i = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">strShowName = "Alternate Slides"</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>Here we’re initializing some variables we’re going to need to set up our slide show. We first set the counter variable i to 1 (we’ll use that in some While loops in just a bit). We’ll also be using a named slide show to accomplish this challenge, so we’ve set the slide show name to <I>Alternate Slides</I>.</P>
<P class=MsoNormal>What exactly is a named slide show, and why are we using it? A named slide show is going to allow us to create a custom slide show without actually rearranging the slides within PowerPoint. It’s sort of a slide show within a slide show. We give this new slide show a name, tell it which slides we want to include, and in what order, then we can refer to that slide show by name and run it.</P>
<P class=MsoNormal>So let’s continue. We’re going to show all the odd-numbered slides first, then the even-numbered slides. That means that we first need to find out how many of each slide type (odd or even) we have. We start by setting a couple of temporary variables, then using those variables to determine how many odd-numbered slides we have and how many even-numbered slides:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">temp1 = slideCount / 2</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">temp2 = slideCount Mod 2</SPAN></P>
<P class=MsoNormal>The variable temp1 holds the number of slides divided by 2. So if there are 7 slides, temp1 is equal to 3. Keep in mind that we’re using integers here, so we don’t have any fractional values, just whole numbers. If there were an even number of slides in the presentation, we could simply divide the number of slides in half and know that one half are odd and one half are even. But we don’t know that, there might be an odd number of slides. To find out we set temp2 to the remainder of slideCount divided by 2, which is what the Mod function does. In our example of 7 slides, the remainder (Mod) of slideCount divided by 2 is 1. </P>
<P class=MsoNormal>Now we can determine how many even-numbered slides we have and how many odd-numbered slides. We have temp1 (3) even-numbered slides (slides 2, 4, 6) and temp1 plus temp2 (4) odd-numbered slides (3+1=4: slides 1, 3, 5, 7). Here’s how we determined that in our code:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">o = temp1 + temp2</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">e = temp1</SPAN></P>
<P class=MsoNormal>When you run a named slide show you need to provide an array that the slide IDs of each slide to show in the order you want to show them. We’re going to create that array by first creating an array of odd-numbered slides and then an array of even-numbered slides. We’ll then put those two arrays together to create the final slide show.</P>
<P class=MsoNormal>Let’s start with the array of odd-numbered slides:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">j = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">While (i &lt;= o)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; arrOdd(i) = ActivePresentation.Slides(j).SlideID</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; j = j + 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; i = i + 1</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">Wend</SPAN></P>
<P class=MsoNormal>We’re going to loop through the slides while our counter variable i is less than or equal to the number of odd-numbered slides in the presentation. Each time through the loop we add the slide ID of one slide to the array arrOdd:</P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">arrOdd(i) = ActivePresentation.Slides(j).SlideID</SPAN></P>
<P class=MsoNormal>Notice we’ve set another counter variable, j, to 1. This variable tells us which slide in the presentation we’re adding to the array. Thus, the first time through the While loop we add the SlideID of slide j (1) to array position i (1). We then increment j by 2 and i by 1:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">j = j + 2</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">i = i + 1</SPAN></P>
<P class=MsoNormal>Why did we increment j by 2? You got it: because we’re only adding odd-numbered slides, which means we add every other slide. As a result, the second time through the loop we’ll be adding the next odd-numbered slide, slide 3, to the array.</P>
<P class=MsoNormal>After we have all the odd-numbered slides in an arrOdd, we reset our counters and do the same with the even-numbered slides, adding them to arrEven:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">j = 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">i = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">While (i &lt;= e)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; arrEven(i) = ActivePresentation.Slides(j).SlideID</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; j = j + 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; i = i + 1</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">Wend</SPAN></P>
<P class=MsoNormal>Notice that our counter j started at 2; that’s because we’re doing even-numbered slides, which means we start with slide 2 and add slides 4, 6, etc. to the array.</P>
<P class=MsoNormal>Finally, we put these two arrays together into a new array (arrAll), first putting in everything from arrOdd and then everything from arrEven:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">i = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">j = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">While (i &lt;= o)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; arrAll(i) = arrOdd(i)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; i = i + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Wend</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">While (j &lt;= e)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; arrAll(i) = arrEven(j)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; j = j + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; i = i + 1</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">Wend</SPAN></P>
<P class=MsoNormal>You might have noticed that we didn’t reset our counter i between the two While loops. That’s because, after we add the odd-numbered slides to the new array, we want to start at the next position in that array and begin adding the even-numbered slides.</P>
<P class=MsoNormal>Now it’s time to set some properties for our slide show:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">i = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">While (i &lt;= slideCount)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; With ActivePresentation.Slides(i).SlideShowTransition</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .AdvanceOnTime = msoCTrue</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .AdvanceTime = 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; End With</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; i = i + 1</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">Wend</SPAN></P>
<P class=MsoNormal>Here we’re going through each of the slides and setting the transition properties using the <A href="https://msdn.microsoft.com/en-us/library/bb265582.aspx" mce_href="https://msdn.microsoft.com/en-us/library/bb265582.aspx"><B>SlideShowTransition</B></A> object. We set the <B>AdvanceOnTime</B> property to msoCTrue, meaning we want the slides to transition based on a set amount of time, then we set the <B>AdvanceTime</B> property to 2, meaning that set amount of time is 2 seconds.</P>
<P class=MsoNormal>And then it’s time to actually create our named slide show. We do this by calling the <B>Add</B> method of the <A href="https://msdn.microsoft.com/en-us/library/bb230533.aspx" mce_href="https://msdn.microsoft.com/en-us/library/bb230533.aspx"><B>NamedSlideShows</B></A> property:</P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">ActivePresentation.SlideShowSettings.NamedSlideShows.Add strShowName, arrAll</SPAN></P>
<P class=MsoNormal>We pass two parameters to the Add method: strShowName, the name of our slide show; and arrAll, the array containing the slide IDs of our show.</P>
<P class=MsoNormal>And now, finally, we can start the show:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">With ActivePresentation.SlideShowSettings</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .RangeType = ppShowNamedSlideShow</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .SlideShowName = strShowName</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .Run</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">End With</SPAN></P>
<P class=MsoNormal>We need to set two properties before the slide show can start: <B>RangeType</B> and <B>SlideShowName</B>. We set RangeType to ppShowNamedSlideShow to – yes, that’s right, to specify that we’re going to be running a named slide show. Then we have to specify <I>which</I> named slide show; we do that by setting SlideShowName to the name of the slide show (strShowName). Now all we have to do is call the <B>Run</B> method and our slide show will begin.</P>
<P class=MsoNormal>When we were testing our own solution, we ran into one problem: if we ran this subroutine to watch our slide show, then enjoyed it so much that we stopped it and ran it again, the code crashed. The reason it crashed was because we called the Add method to create the named slide show. That’s fine, except that, when we ran the code a second time, the Add method realized that a slide show by that name already existed. Because of that, the Add method refused to add another slide show by the same name and the whole thing crashed.</P>
<P class=MsoNormal>Rather than worry about checking for existing slide shows or making sure each slide show name was unique, we simply deleted all named slide shows at the end of the subroutine, and asked you to do the same:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">For Each customShow In ActivePresentation.SlideShowSettings.NamedSlideShows</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; customShow.Delete</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">Next customShow</SPAN></P>
<P class=MsoNormal>Here we’re using a For loop to cycle through the collection of named slide shows and delete each one.</P>
<P class=MsoNormal>Whew! That was a pretty tough challenge for novices, wasn’t it? If Binder Clippy had been here to help it might have been a little easier. </P>
<P class=MsoNormal>Well, maybe not….</P></DIV>]]></content:encoded>
    </item>
    <item>
      <title>Solution - Novice Challenge 9: I Need a Break</title>
      <link>https://docs.microsoft.com/archive/blogs/officepalooza/solution-novice-challenge-9-i-need-a-break</link>
      <pubDate>Fri, 01 May 2009 00:42:00 GMT</pubDate>
      <dc:creator><![CDATA[Greg Stemp]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/officepalooza/2009/05/01/solution-novice-challenge-9-i-need-a-break/</guid>
      <description><![CDATA[It’s true: we all need a break once in a while. A break from work, a break from the...]]></description>
      <content:encoded><![CDATA[<META content="Microsoft Word 12 (filtered)" name=Generator>
<STYLE>
<!--
 /* Font Definitions */
 @font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:0in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
	{mso-style-link:"Balloon Text Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:8.0pt;
	font-family:"Tahoma","sans-serif";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:.5in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:.5in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
span.BalloonTextChar
	{mso-style-name:"Balloon Text Char";
	mso-style-link:"Balloon Text";
	font-family:"Tahoma","sans-serif";}
.MsoPapDefault
	{margin-bottom:10.0pt;
	line-height:115%;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 ol
	{margin-bottom:0in;}
ul
	{margin-bottom:0in;}
-->
</STYLE>

<DIV class=Section1>
<P class=MsoNormal>It’s true: we all need a break once in a while. A break from work, a break from the kids, a break from the in-laws...sometimes we just need to power down for a little while and take it easy. But sometimes this <I>can</I> be overdone. The breaks at work come a little too often, or the parents say that you’re not calling often enough. </P>
<P class=MsoNormal><B>Note</B>. What? No, we don’t know anyone like that, and we definitely don’t know anyone who takes too many breaks at work. But we’re sure they’re out there somewhere. </P>
<P class=MsoNormal>Usually none of this is too bad, but what happens when your <I>software</I> takes too many breaks? That’s definitely trouble. And that’s exactly what happened in Challenge 9. We have a Word document that has way too many manual page breaks, and we need to get rid of some of them. As a matter of fact, we need to get rid of <I>all</I> of them. That should be easy, right?</P>
<P class=MsoNormal>But, then again, we didn’t want to make challenge <I>too</I> easy on you. Given the fact that you could have get rid of the manual page breaks by simply recording a macro, we threw in an extra requirement: you had to display a couple of message boxes along the way. Here’s how we accomplished all that:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Sub FindMyBreaks()</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Dim objPages As Pages</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Retrieve a collection of all the pages in the document</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Set objPages = ActiveDocument. _</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; ActiveWindow.Panes(1).Pages</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Display a message box showing the number of pages in the doc.</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">MsgBox "Number of Pages: " &amp; objPages.Count, vbOKOnly, "Document Pages"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Ensures all instances of the search string are found, regardless of formatting</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Selection.Find.ClearFormatting</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Find manual page breaks and paragraph markers that follow them and replace</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">' with nothing.</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">With Selection.Find</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .Text = "^m^p"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .Replacement.Text = ""</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .Forward = True</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .Wrap = wdFindContinue</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">End With</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Selection.Find.Execute Replace:=wdReplaceAll</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Retrieve a collection of all the pages with the manual page breaks removed.</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Set objPages = ActiveDocument. _</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; ActiveWindow.Panes(1).Pages</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">'Display a message box showing the number of pages in the doc.</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">MsgBox "Number of Pages: " &amp; objPages.Count, vbOKOnly, "Document Pages"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">End Sub</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>After declaring the one variable we’re going to need in this subroutine (objPages), we use the <A href="https://msdn.microsoft.com/en-us/library/bb179143.aspx" mce_href="https://msdn.microsoft.com/en-us/library/bb179143.aspx"><B>Pages</B></A> collection to retrieve a collection of all the pages in the current document:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Set objPages = ActiveDocument. _</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; ActiveWindow.Panes(1).Pages</SPAN></P>
<P class=MsoNormal>Now we can accomplish the first step in the instructions for Challenge 9. We need to display a message box that states the number of pages in the current document. We do that by calling the <B>MsgBox</B> function like this:</P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">MsgBox "Number of Pages: " &amp; objPages.Count, vbOKOnly, "Document Pages"</SPAN></P>
<P class=MsoNormal>We pass three parameters to MsgBox. The first is the text we want displayed within the message box:</P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">"Number of Pages: " &amp; objPages.Count</SPAN></P>
<P class=MsoNormal>Here we’re creating a string that begins with “Number of Pages:”. We then tack on the number of pages. And how did we get the number of pages? Well, we just retrieved a collection of all the pages, so all we have to do at that point is count them. In other words, we just need to take a look at the <B>Count</B> property of the Pages collection.</P>
<P class=MsoNormal>Next it’s time to get to work removing those page breaks. The first thing we do is call the <A href="https://msdn.microsoft.com/en-us/library/bb214437.aspx" mce_href="https://msdn.microsoft.com/en-us/library/bb214437.aspx"><B>ClearFormatting</B></A> method of the Find object:</P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">Selection.Find.ClearFormatting</SPAN></P>
<P class=MsoNormal>We do this just to make sure we find all our page breaks, no matter what formatting may have been applied to them.</P>
<P class=MsoNormal>In order to remove the page breaks, we need to find them all and then replace them with nothing. So the next thing we do is set up the find and replace criteria:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">With Selection.Find</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .Text = "^m^p"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .Replacement.Text = ""</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .Forward = True</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; .Wrap = wdFindContinue</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">End With</SPAN></P>
<P class=MsoNormal>Because all of our settings will be applied to the Selection.Find object, we put everything inside a With block; that way we don’t have to keep typing Selection.Find over and over again. (Hey, we’re busy people, we don’t have time for all that typing. Maybe later, when we get a break, we’ll think about doing some more typing.)</P>
<P class=MsoNormal>We set four properties for our find and replace. First we set the Text property, which specifies the string we want to search for:</P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">.Text = "^m^p"</SPAN></P>
<P class=MsoNormal>Wait a minute: didn’t we say we were looking for a page break, not the string ^m^p? Well, as it turns out, the character set ^m represents a manual page break. (How do we know this? In Word, open the Find and Replace dialog box. Click <B>More&gt;&gt;</B>, click <B>Special</B>, and then select <B>Manual Page Break</B>. You’ll see the characters ^m in the <B>Find what</B> text box.)</P>
<P class=MsoNormal>To solve this challenge (and receive your goldfish) that’s all you had to search for. But when we ran find and replace with ^m as the text string, we wound up with extra paragraph breaks in our text. Therefore we added ^p to our string, which represents a paragraph mark. Thus we’re searching for both a manual page break and the paragraph return that follows it.</P>
<P class=MsoNormal>Now that we’ve set the text we want to find, we set the value of the <B>Replacement.Text</B> property to the value we want to use as the replacement text. In our case we just want to delete the page break, so we replace it with an empty string (nothing):</P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">.Replacement.Text = ""</SPAN></P>
<P class=MsoNormal>We’re starting our find and replace from the beginning of the document, so we set the <B>Forward</B> property to True, saying we want to do a forward search (rather than start at the end and search backwards):</P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">.Forward = True</SPAN></P>
<P class=MsoNormal>Finally, we set the <B>Wrap</B> property to the constant <B>wdFindContinue</B>:</P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">.Wrap = wdFindContinue</SPAN></P>
<P class=MsoNormal>We’ve all seen this before: we’re somewhere in the middle of the document, we do a Find, and when we reach the end of the document Word pops up a box asking if we’d like to continue searching from the top. Setting the Wrap property to wdFindContinue is like clicking Yes to that dialog box. In other words, if our search reaches the end of the document before the whole document has been searched, the search will automatically continue from the beginning. This is nice, because we don’t want any stray message boxes popping up in middle of running our macro.</P>
<P class=MsoNormal>We’ve now set all the properties for our find and replace, which means it’s time to actually run it:</P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">Selection.Find.Execute Replace:=wdReplaceAll</SPAN></P>
<P class=MsoNormal>As you can see, we’re calling the <B>Execute</B> method on the Find object to run our find and replace. Note that we set the Replace parameter to <B>wdReplaceAll</B>; this ensures that every instance of the find string will be replaced, not just the first one.</P>
<P class=MsoNormal>Okay, we’ve done the hard part; now there’s only one thing left to do. Now that we’ve removed all the manual page breaks, we want to see how many pages we’re left with. That’s actually pretty simply. We just run the exact same code we ran at the beginning of the subroutine to retrieve all the pages, then output the page count to a message box:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">Set objPages = ActiveDocument. _</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; ActiveWindow.Panes(1).Pages</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'">MsgBox "Number of Pages: " &amp; objPages.Count, vbOKOnly, "Document Pages"</SPAN></P>
<P class=MsoNormal>Because we’re calling the same code twice, it might be a good idea to put that section of code in a new subroutine and simply call the subroutine twice. But we put in the instructions for these challenges that we didn’t want you to do that (it’s much easier to test single subroutines); because of that, we asked you to break a useful coding standard for ease of testing. We just thought we’d mention that when you’re coding for real and not playing OfficePalooza games, this type of thing would be a good candidate for creating an additional subroutine.</P>
<P class=MsoNormal>That’s the lesson for today, and the end of Challenge 9. We’re going to take a break now. See you later.</P></DIV>]]></content:encoded>
    </item>
    <item>
      <title>Solution - Experienced Challenge 10: Don’t Get Ten of Those Little Red Cells</title>
      <link>https://docs.microsoft.com/archive/blogs/officepalooza/solution-experienced-challenge-10-dont-get-ten-of-those-little-red-cells</link>
      <pubDate>Fri, 01 May 2009 00:41:00 GMT</pubDate>
      <dc:creator><![CDATA[Greg Stemp]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/officepalooza/2009/05/01/solution-experienced-challenge-10-dont-get-ten-of-those-little-red-cells/</guid>
      <description><![CDATA[You know, if we were a little smarter we would have made Challenge 10 an easy one; after...]]></description>
      <content:encoded><![CDATA[<META content="Microsoft Word 12 (filtered)" name=Generator>
<STYLE>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:0in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:.5in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:.5in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
.MsoPapDefault
	{margin-bottom:10.0pt;
	line-height:115%;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 ol
	{margin-bottom:0in;}
ul
	{margin-bottom:0in;}
-->
</STYLE>

<DIV class=Section1>
<P class=MsoNormal>You know, if we were a little smarter we would have made Challenge 10 an easy one; after 2 solid weeks of copying Visual Basic for Applications (VBA) subroutines from emails, pasting those subroutines into a Microsoft Office application, and then running that subroutine to make sure it actually worked, well, we definitely could have used a break here. But did we take the easy way out? Heck no; instead, Challenge 10 was the most difficult one to test, if for no other reason than the fact that it required at least two subroutines, subroutines which had to be stashed in two totally different places. (One, the NewGame subroutine, had to go in Module1; the other subroutine had to be attached to Sheet1.) What were we <I>thinking</I>?</P>
<P class=MsoNormal><B>Note</B>. Well, obviously we weren’t thinking . After all, if we’d done even a <I>little</I> thinking we never would have agreed to do OfficePalooza in our spare time, something which meant we’d work all day at our real jobs and then go home and work all night on OfficePalooza. But, then again, OfficePalooza <I>was</I> a lot of fun, and we enjoyed seeing the different ways in which people approached the challenges. Maybe it’s a good thing that we <I>don’t</I> do much thinking after all! Something to think about, eh?</P>
<P class=MsoNormal>We also made our lives a bit more complicated by deciding to solve Challenge 10 without using global variables. Admittedly, we <I>could</I> have used global variables; there’s nothing in the instructions that say otherwise, and we happily accepted all the submissions that took that approach. However, global variables meant yet another piece of code that had to be placed in a specific spot in the workbook; that complicates our testing process. Had we been thinking, we would have said, “Do not use global variables in your submission.” But – well, you already know how we are when it comes to thinking.</P>
<P class=MsoNormal><B>Note</B>. On top of that, we had a bad habit of posting the challenge and only then trying to determine if the challenge could actually be solved. We couldn’t rule out the use of global variables simply because, at the time the challenge was unveiled, we didn’t know for sure if you <I>could</I> solve the problem without using global variables. Wouldn’t it have been better to think about that <I>before</I> we posted the challenge? </P>
<P class=MsoNormal>You already know the answer to <I>that</I> question.</P>
<P class=MsoNormal>At any rate, global variables or no global variables, we eventually came up with a pair of subroutines that could play a rudimentary game of Hangman. And just what <I>are</I> those subroutines? Well, here’s one of them, the NewGame subroutine (the one we put in Module1):</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Sub NewGame()</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Sheet1.Unprotect</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Range("B5:N6").Cells.Interior.ColorIndex = 2&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Range("S5:S14").Cells.Interior.ColorIndex = 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Range("B8:N8").Cells.Interior.ColorIndex = 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Range("B8:N8").Cells.Value = ""</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Do While True</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intWordRow = Int((Rnd * 32154) + 1)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strNewWord = Sheet2.Cells(intWordRow, 1).Value</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intLength = Len(strNewWord)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If intLength &gt; 6 And intLength &lt; 14 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 1 To intLength</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Application.Cells(8, i + 1).Interior.ColorIndex = 6</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Application.Cells(8, i + 1).Font.ColorIndex = 6</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Application.Cells(8, i + 1).Value = UCase(Mid(strNewWord, i, 1))</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sheet1.Protect</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Do</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Loop</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">End Sub</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>The NewGame subroutine, as you can probably guess, is all about getting the worksheet ready for a new game. In order to play the game, you need to click on the list of available letters (cells B5 through N6). When you click on a letter, that particular cell should turn gray (indicating the letter has been chosen) and the value of that cell needs to be immediately available for use. The only way we can do that (well, that we know of anyway) is to protect the worksheet; if the worksheet is unprotected then clicking on a cell will simply select that cell. That’s not what we want. In addition to that, by protecting the worksheet we can keep people from clicking where they shouldn’t. (For example, people can’t select and delete any cells on the worksheet, something which could definitely wreak a little havoc on game play.)</P>
<P class=MsoNormal>OK, so if we need to have the worksheet protected then why does our very first line of code call the <I>Unprotect</I> method? Good question. In order to set up a new game we need to make some changes to the worksheet; for example, we need to reset the background colors of some of our cells. We can’t do that if the worksheet is protected; when that’s the case you can’t make <I>any</I> changes to the worksheet, even using VBA. The only way we <I>can</I> make changes is to unprotect the sheet. But don’t worry: the change in protection status will only be temporary.</P>
<P class=MsoNormal>Next we execute the following block of code:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Range("B5:N6").Cells.Interior.ColorIndex = 2&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Range("S5:S14").Cells.Interior.ColorIndex = 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Range("B8:N8").Cells.Interior.ColorIndex = 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Range("B8:N8").Cells.Value = ""</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>All we’re doing here (for the most part) is resetting the background colors of selected cells on the worksheet. For example, cells B5 through N6 are the letters you can use while playing the game; cells S5 through S14 represent the “scoreboard,” the portion of the game where we keep track of your incorrect guesses. In both cases, we set the <B>ColorIndex</B> property of each cell in the range to 2 (which just happens to be white). We also do the same thing with cells B8 through N8, the place where our “secret word” is displayed. In addition to changing the background color of these cells we also set the <B>Value</B> of each cell to an empty string; that simply clears the cell so that we can enter a new letter in there.</P>
<P class=MsoNormal>At this point we’re ready to select a new secret word. To carry out that chore, the first thing we do is set up a Do loop designed to run forever (or at least for as long as True is equal to True). Why do we need a loop here? Well, we put a couple stipulations on our word selection; in particular, we said that a word must have at least 7 letters but no more than 13 letters. We need this loop just in case, the first time around, we randomly choose a word that only has, say, 5 letters.</P>
<P class=MsoNormal><B>Note</B>. As it turns out, our list of words – which we downloaded off the Internet – includes some two-word “words” (words separated by a blank space), plus words that have hyphens or other non-letter characters in them. Ideally, we would have written code that tossed out any words that included anything other than the letters A through Z; in the interest of keeping this subroutine short and sweet we opted not to do that. At least some of you <I>did</I> include code that guarded against selecting a secret word that included a blank space or a hyphen. All we can say is this: good for you!</P>
<P class=MsoNormal>Inside the loop we first call the <B>Rnd</B> function to select a random number between 1 and 32154. (Why 32154? Because we have that many words listed on Sheet2 of the workbook.) This line of code selects a value between 1 and 32154, then uses the <B>Int</B> function to convert that value to an integer:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">intWordRow = Int((Rnd * 32154) + 1)</SPAN></P>
<P class=MsoNormal>The selected value actually represents a row on Sheet2 of our workbook. Now that we have a row number we can use this line of code to grab the value of the word listed on row <I>intWordRow</I>, column 1:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">strNewWord = Sheet2.Cells(intWordRow, 1).Value</SPAN></P>
<P class=MsoNormal>After we’ve selected a word we can next use the <B>Len</B> function to determine the total number of characters in that word. Once that’s done we use this line of code to verify that the word has at least 7 (but no more than 13) characters in it:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">If intLength &gt; 6 And intLength &lt; 14 Then</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>If the secret word doesn’t meet these criteria we simply pop back to the top of the loop and try again. If the secret word <I>does</I> meet these criteria then we execute the following block of code:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">For i = 1 To intLength</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Application.Cells(8, i + 1).Interior.ColorIndex = 6</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Application.Cells(8, i + 1).Font.ColorIndex = 6</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Application.Cells(8, i + 1).Value = UCase(Mid(strNewWord, i, 1))</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Next</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>All we’ve done here is set up a loop that runs from 1 (representing the first character in the secret word) to the length of that secret word (representing the last character in the word.) Inside the loop we start with the first cell in the range B8 through N8; as you no doubt figured out, cell row 8, column 2 (i + 1) is the same thing as cell B8. For this first cell we set the background color of the cell to yellow (6); we also set the <B>Font</B> color of the cell to yellow. Why do we bother with the font color? Well, as we noted earlier, we wanted to be able to play this game without needing to use global variables. One simple way of doing this (as some of you discovered) is to make the font color the same color as the background color of the cell. When the two colors are identical, we can then enter the correct letter in the cell; no one will be able to see it, but it will be there. This line of code (the first time through the loop) simply takes the first letter in our secret word and types it into cell B8.</P>
<P class=MsoNormal>We then loop around and repeat the process with the next cell in the range B8 through N8 and the next letter in the secret word.</P>
<P class=MsoNormal>And once <I>that’s</I> done we simply call the <B>Protect</B> method to reprotect our worksheet, then call <B>Exit Do</B> to exit the NewGame subroutine:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Sheet1.Protect</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Exit Do</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>All things considered, that wasn’t too terribly bad, was it?</P>
<P class=MsoNormal>Next we need to create a single subroutine for actually playing the game. The best way to do that? Well, we’re not exactly sure if this is the <I>best</I> way to do that. But what worked for us was to add the following subroutine to Sheet1 in the workbook:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Public Sub Worksheet_SelectionChange(ByVal objTarget As Range)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Set objRange = Range(objTarget.Address)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Set objRange2 = Range("B5:N6")</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Set isect = Application.Intersect(objRange2, objRange)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; If Not isect Is Nothing Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sheet1.Unprotect</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objTarget.Cells.Interior.ColorIndex = 16</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = 0</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each objCell In Range("B8:N8").Cells</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If objCell.Value = objTarget.Cells.Value Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objCell.Font.ColorIndex = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objCell.Interior.ColorIndex = 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If x = 0 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each objCell In Range("S5:S14").Cells</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If objCell.Interior.ColorIndex &lt;&gt; 3 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objCell.Interior.ColorIndex = 3</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit For</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sheet1.Protect</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; If Application.Cells(14, 19).Interior.ColorIndex = 3 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strValue = ""</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each objCell In Range("B8:N8").Cells</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strValue = strValue &amp; objCell.Value</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "Sorry; you lose. The word was " &amp; strValue &amp; "."</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sheet1.Protect</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; intWordLength = 0</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; For Each objCell In Range("B8:N8").Cells</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If objCell.Interior.ColorIndex = 6 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intWordLength = intWordLength + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Next</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; If intWordLength = 0 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><A class="" title=OLE_LINK2 name=OLE_LINK2></A><A class="" title=OLE_LINK1 name=OLE_LINK1></A><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "Congratulations; you win!"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sheet1.Protect</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">End Sub</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>As you can see, this subroutine is designed to respond any time the selection changes on the worksheet (hence the reference to the <B>Worksheet_SelectionChange</B> event). Any time a player clicks a cell on Sheet1 (any cell on Sheet1) the SelectionChange event will be triggered, and this subroutine will run.</P>
<P class=MsoNormal>So what will this subroutine do when it <I>does</I> run? Well, for starters, it creates a pair of Range objects:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Set objRange = Range(objTarget.Address)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Set objRange2 = Range("B5:N6")</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>In the first line of code, we create a Range object that represents the cell that the player clicked; that’s what the <B>objTarget.Address</B> is for. And in line 2? In that line we create a range object that represents the collection of available letters (that is, cells B5 through N6).</P>
<P class=MsoNormal>That brings us to this line of code:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">Set isect = Application.Intersect(objRange2, objRange)</SPAN></P>
<P class=MsoNormal>Here we’re using the <B>Intersect</B> method to see if the cell that the user clicked intersects with the collection of available letters; in other words, did we click on a cell located in the range B5 through N6? If we did, then the object reference isect will be a valid object. And if we <I>didn’t</I> click on a cell located in range B5 through N6? In that case, isect will <I>not</I> point to a valid object.</P>
<P class=MsoNormal>Which explains why we next execute this line of code:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">If Not isect Is Nothing Then</SPAN></P>
<P class=MsoNormal>What we’re doing here is checking to make sure isect represents a valid object. If we don’t have a valid object (that is, if isect is equal to <B>Nothing</B>) then we simply exit the subroutine and wait for the player to click a new cell on the spreadsheet. And if we have a <I>valid</I> object? Well, in that case the first thing we do is run these two lines of code:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Sheet1.Unprotect</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objTarget.Cells.Interior.ColorIndex = 16</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>In line 1 we, again, unprotect our worksheet. (Why? Because we need to make some changes to that worksheet.) We then set the ColorIndex of the selected cell to a dark gray (16); that way the player will be able to tell, at a glance, that he or she has already selected that particular letter.</P>
<P class=MsoNormal>After setting the value of the counter variable x to 0 (more on that in a minute) we execute this block of code:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">For Each objCell In Range("B8:N8").Cells</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; If objCell.Value = objTarget.Cells.Value Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;objCell.Font.ColorIndex = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objCell.Interior.ColorIndex = 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">Next</SPAN></P>
<P class=MsoNormal>Admittedly, this is a tiny bit clunky; that’s because (we we mentioned earlier) we wanted to come up with a solution that required just two subroutines and no global variables. What we’re doing here is simply checking to see if the selected letter appears anywhere in the secret word. There are more elegant ways to do this; most of those ways would require the use of a global variable, however. Consequently, we do this the old-fashioned, brute force way: by setting up a For Each loop that checks each cell in the range B8 through N8 to see if the Value of any of those cells matches the value of the selected cell (that is, the letter that the player clicked on). This line of code checks to see if the values match:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">If objCell.Value = objTarget.Cells.Value Then</SPAN></P>
<P class=MsoNormal>If the values don’t match then we don’t do anything; if the values <I>do</I> match we run these 3 lines of code:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objCell.Font.ColorIndex = 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objCell.Interior.ColorIndex = 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">x = 1</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>What are we doing here? Well, to begin with, we’re setting the font color for the cell to black (1); that’s going to allow the hidden value to “magically” appear on screen. After changing the font color we then change the background color of the cell to white; we do that so the player knows that he or she has correctly identified the letter that goes in that space. Finally, we set the value of x to 1; that helps us keep track of the fact that the selected letter does appear <I>somewhere</I> in the secret word. </P>
<P class=MsoNormal>Got all that? Good. Then here’s what we do next:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">If x = 0 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; For Each objCell In Range("S5:S14").Cells</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If objCell.Interior.ColorIndex &lt;&gt; 3 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objCell.Interior.ColorIndex = 3</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit For</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Next</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">End If</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>Remember how we set the value of x to 1 if the selected letter appears somewhere in the secret word? Well, if the letter <I>doesn’t</I> appear anywhere in the word that means that x will still be equal to 0 (and that the user made a wrong guess). In that case we need to change one of the cells in our scoreboard to red.</P>
<P class=MsoNormal>Ah, yet another good question: <I>which</I> cell do we need to change to red? To tell you the truth, we don’t know; this is another case where a global variable would come in handy. But even without a global variable we can still figure out which cell needs to be updated. How? By looping through the cells in range S5 through S14 and checking to see if the background color is red. If it is, then we go back to the top of the loop and try again with the next cell in the range. If it isn’t? Then we use this line of code to change the background color to red:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">objCell.Interior.ColorIndex = 3</SPAN></P>
<P class=MsoNormal>Like we said, not particularly elegant. But it works.</P>
<P class=MsoNormal>OK, so the user has selected a letter, we’ve determined whether or not that letter can be found in the secret word, and, if need be, we’ve updated our scoreboard. Now what do we do? </P>
<P class=MsoNormal>Well, first we need to check to see if the player has lost the game. How can we determine if the player has lost the game? Here’s one way. If the player has made 10 incorrect guesses then cell S14 will have a background color of red. We can check the background color of that cell using this line of code:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">If Application.Cells(14, 19).Interior.ColorIndex = 3 Then</SPAN></P>
<P class=MsoNormal>If the color <I>is </I>red then we run this block of code:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">strValue = ""</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">For Each objCell In Range("B8:N8").Cells</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; strValue = strValue &amp; objCell.Value</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Next</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">MsgBox "Sorry; you lose. The word was " &amp; strValue &amp; "."</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Sheet1.Protect</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Exit Sub</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>In the first four lines we simply loop through the values in cells B8 through N8 and use the letters found in each cell to reconstruct our secret word. (Needless to say, if we were using global variables we wouldn’t have to do this.) After the secret word has been stashed in the variable strValue we use this line of code to echo back the fact that the player has lost and, just to be nice, let him or her know what the secret word actually was:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">MsgBox "Sorry; you lose. The word was " &amp; strValue &amp; "."</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>We then reprotect the worksheet and exit the subroutine.</P>
<P class=MsoNormal>But suppose the player <I>hasn’t</I> lost; does that mean the he or she has won? To be honest, we don’t know; however, we can figure that out by looping through the cells in range B8 through N8 and checking to see if the background color of any of those cells is yellow:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">intWordLength = 0</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">For Each objCell In Range("B8:N8").Cells</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; If objCell.Interior.ColorIndex = 6 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intWordLength = intWordLength + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Next</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>If we happen to encounter a yellow cell we increment the value of the counter variable intWordLength by 1. When we’re done we’ll check the value of intWordLength. If intWordLength is equal to 0 that means we didn’t find any yellow cells; in turn, that means that the player has won. If intWordLength is anything <I>but</I> 0 that means that the player hasn’t guessed all the letters correctly and the game is still on. In that case, we don’t do much of anything except wait for the player to select another letter.</P>
<P class=MsoNormal>If our player <I>has</I> won then we congratulate them, reprotect the spreadsheet, and exit the subroutine; that’s what this hunk of code is for:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">MsgBox "Congratulations; you win!"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Sheet1.Protect</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Exit Sub</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>And, believe it or not, that’s all we have to do. Game over!</P>
<P class=MsoNormal>Or so we think.</P></DIV>]]></content:encoded>
    </item>
    <item>
      <title>Solution - Experienced Challenge 9: And They’re Off!</title>
      <link>https://docs.microsoft.com/archive/blogs/officepalooza/solution-experienced-challenge-9-and-theyre-off</link>
      <pubDate>Fri, 01 May 2009 00:40:00 GMT</pubDate>
      <dc:creator><![CDATA[Greg Stemp]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/officepalooza/2009/05/01/solution-experienced-challenge-9-and-theyre-off/</guid>
      <description><![CDATA[This was one challenge that we actually had to think about. (Does that mean we didn’t...]]></description>
      <content:encoded><![CDATA[<META content="Microsoft Word 12 (filtered)" name=Generator>
<STYLE>
<!--
 /* Font Definitions */
 @font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:0in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
.MsoPapDefault
	{margin-bottom:10.0pt;
	line-height:115%;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
	{page:Section1;}
-->
</STYLE>

<DIV class=Section1>
<P class=MsoNormal>This was one challenge that we actually had to think about. (Does that mean we didn’t think about the other challenges? Um, well ….) That’s because we were initially tempted to try and use Microsoft Office PowerPoint’s animation capabilities to try and create a very smooth, very realistic-looking race. But the more we thought about it, the more we realized that doing something like that was going to take a <I>lot</I> of thinking. Seeing as how thinking isn’t really our specialty, we thought better of it and decided to use a more brute force approach: we’d pick a horse, move it a little closer to the finish line; pick a horse, move it a little closer to the finish line; and so on. It’s not as elegant, but it works. And, as you’re about to see, it works with a minimal amount of code:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Private Sub CommandButton2_Click()</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Set myDocument = ActivePresentation.Slides(1)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Do While True</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If myDocument.Shapes(6).Left &gt; 525 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "Blue wins!"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If myDocument.Shapes(7).Left &gt; 525 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "Red wins!"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If myDocument.Shapes(8).Left &gt; 525 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "Green wins!"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If myDocument.Shapes(9).Left &gt; 525 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "Brown wins!"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Randomize</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intDie = Int(Rnd() * 4) + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Randomize</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intMover = Int(Rnd() * 10) + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select Case intDie</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myDocument.Shapes(6).IncrementLeft intMover</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myDocument.Shapes(7).IncrementLeft intMover</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case 3</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myDocument.Shapes(8).IncrementLeft intMover</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case 4</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myDocument.Shapes(9).IncrementLeft intMover</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Select</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DoEvents</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Loop</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">End Sub</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>We start things out by creating an object reference to slide 1 in our presentation. (Which, now that we think about it, is the <I>only</I> slide in our presentation.) That’s what this line of code is for:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">Set myDocument = ActivePresentation.Slides(1)</SPAN></P>
<P class=MsoNormal>Believe it or not, that’s it for preparation and setup; at this point, we’re ready to start racing.</P>
<P class=MsoNormal>To conduct the race itself, we set up a Do Loop designed to run as long as True is equal to True. (And yes, that means if True is ever equal to False then our race will end prematurely. But that was a risk we were willing to take.) Inside the loop we have a series of four code blocks, code blocks designed to see whether any of our four horses have hit the finish line. For example, the block of code that tracks the progress of the blue horse (Shape 6) looks like this:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">If myDocument.Shapes(6).Left &gt; 525 Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; MsgBox "Blue wins!"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp; &nbsp;&nbsp;Exit Sub</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">End If</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>All we’re doing here is seeing if the left edge of our horse (as determined by the <B>Left</B> property) is greater than or equal to 525. If it is, that means that the blue horse has crossed the finish line and is the winner. In turn, we display the message “Blue wins!” and then exit the subroutine, a move that also brings the race to a close.</P>
<P class=MsoNormal><B>Note</B>. How did we know that 525 was the magic number that would mean a horse has crossed the finish line? That was actually pretty easy: we simply placed one of the horses on the finish line and then wrote a temporary subroutine that displayed the value of the horse’s <B>Left</B> property. </P>
<P class=MsoNormal>And yes, as far as we know that <I>is</I> the way they determine the winner in real horse races.</P>
<P class=MsoNormal>These first four blocks of code tell us which horse crossed the finish line first. However, how do we actually get those horses <I>to</I> the finish line? Well, our solution was to move a random horse a random amount, and to repeat this process until one of the horses crosses the finish line. To help us move a random horse a random amount we execute these lines of code:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Randomize</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">intDice = Int(Rnd() * 4) + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Randomize</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">intMover = Int(Rnd() * 10) + 1</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>In the first two lines we’re rolling a four-sided die in order to determine which horse we’re going to move. (How in the world could you have a die with just four sides? You know, we never thought of that ….) To simulate the rolling of a four-sided die (we’d prefer to use the word “dice” as well, but our editor insists the dice is plural and die is singular) we first call the <B>Randomize</B> function; this “reseeds” the random number generator and helps ensure that we actually get a random number. (If you don’t call the Randomize function you run the risk of getting the same number each time you roll the dice. Uh, die.)</P>
<P class=MsoNormal>In the second line, we use the <B>Rnd</B> function to generate a random number between 1 and 4, inclusive. (We also use the <B>Int</B> function to ensure that we get an integer value.) The net effect? We’re going to get a 1, 2, 3, or 4, one number for each of our horses.</P>
<P class=MsoNormal>In the next two lines we generate a random number that determines the number of points we’re going to move the designated horse. In this case, we’re going to move the horse 1 point, 10 points, or any number of points in between.</P>
<P class=MsoNormal>That brings us to this block of code:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Select Case intDice</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Case 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myDocument.Shapes(6).IncrementLeft intMover</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Case 2</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myDocument.Shapes(7).IncrementLeft intMover</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Case 3</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myDocument.Shapes(8).IncrementLeft intMover</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Case 4</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myDocument.Shapes(9).IncrementLeft intMover</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">End Select</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>What we’ve done is set up a Select Case block that enables us to grab the desired horse and move him (or her; it’s hard to tell the difference with clip art horses) the correct number of points. As you can see, there’s nothing particularly complicated about the code. If our die came up with a 1 we move the blue horse (Shape 6) the correct number of points. (That number, of course, is stored in the variable intMover.) If our die came up with a 2 we move the red horse (Shape 7). If our die came up with a 3 – well, you get the idea.</P>
<P class=MsoNormal>After moving one of the horses we call <B>DoEvents</B>; this helps ensure that we actually <I>see</I> the race unfold onscreen. Otherwise we’d click the button, the subroutine would run, the horses would move to their final position and only <I>then</I> would the screen change. It’s way faster, true. But not nearly as exciting.</P>
<P class=MsoNormal>And then we simply pop back to the top of the loop and repeat the process until we have a winner.</P>
<P class=MsoNormal>Just like the Kentucky Derby.</P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal mce_keep="true">&nbsp;</P></DIV>]]></content:encoded>
    </item>
    <item>
      <title>Day 9</title>
      <link>https://docs.microsoft.com/archive/blogs/officepalooza/day-9</link>
      <pubDate>Thu, 30 Apr 2009 10:38:00 GMT</pubDate>
      <dc:creator><![CDATA[Greg Stemp]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/officepalooza/2009/04/30/day-9/</guid>
      <description><![CDATA[Day 9 of OfficePalooza. Yes, that’s right, Day 9. Only one more day left. But don’t be sad, just...]]></description>
      <content:encoded><![CDATA[<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT face=Calibri size=3>Day 9 of OfficePalooza. Yes, that’s right, Day 9. Only one more day left. But don’t be sad, just make sure you get the final two events done by 8:00 AM PDT tomorrow (Friday, May 1, 2009).</FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT face=Calibri size=3>But before you do that, take a look at some of the great information we have available in celebration of </FONT><A href="https://blogs.msdn.com/officepalooza/pages/9556066.aspx"><B style="mso-bidi-font-weight: normal"><FONT face=Calibri size=3>Microsoft Office Project Day</FONT></B></A><FONT face=Calibri size=3>.</FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Day 8</title>
      <link>https://docs.microsoft.com/archive/blogs/officepalooza/day-8</link>
      <pubDate>Wed, 29 Apr 2009 11:04:00 GMT</pubDate>
      <dc:creator><![CDATA[Greg Stemp]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/officepalooza/2009/04/29/day-8/</guid>
      <description><![CDATA[It’s Day 8, and Challenges 7 and 8 were due this morning. Scores are still being updates as more...]]></description>
      <content:encoded><![CDATA[<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT face=Calibri size=3>It’s Day 8, and </FONT><A href="https://blogs.msdn.com/officepalooza/pages/9556054.aspx"><B style="mso-bidi-font-weight: normal"><FONT face=Calibri size=3>Challenges 7 and 8</FONT></B></A><FONT face=Calibri size=3> were due this morning. Scores are still being updates as more entries come in. Take a look to see how you did (</FONT><A href="https://blogs.msdn.com/officepalooza/pages/9557639.aspx"><B style="mso-bidi-font-weight: normal"><FONT face=Calibri size=3>Novice</FONT></B></A><FONT face=Calibri size=3>, </FONT><A href="https://blogs.msdn.com/officepalooza/pages/9557300.aspx"><B style="mso-bidi-font-weight: normal"><FONT face=Calibri size=3>Experienced</FONT></B></A><FONT face=Calibri size=3>). Only two more challenges to go!</FONT></P>
<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><FONT face=Calibri size=3>And guess what? Today is </FONT><A href="https://blogs.msdn.com/officepalooza/pages/9556066.aspx"><B style="mso-bidi-font-weight: normal"><FONT face=Calibri size=3>Microsoft Office PowerPoint Day</FONT></B></A><FONT face=Calibri size=3>!</FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Solution - Experienced Challenge 8: Twenty Questions</title>
      <link>https://docs.microsoft.com/archive/blogs/officepalooza/solution-experienced-challenge-8-twenty-questions</link>
      <pubDate>Wed, 29 Apr 2009 00:57:00 GMT</pubDate>
      <dc:creator><![CDATA[Greg Stemp]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/officepalooza/2009/04/29/solution-experienced-challenge-8-twenty-questions/</guid>
      <description><![CDATA[So were we able to come up with a solution to challenge 8? Good question. As it turns...]]></description>
      <content:encoded><![CDATA[<META content="Microsoft Word 12 (filtered)" name=Generator>
<STYLE>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:0in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:.5in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:.5in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
.MsoPapDefault
	{margin-bottom:10.0pt;
	line-height:115%;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 ol
	{margin-bottom:0in;}
ul
	{margin-bottom:0in;}
-->
</STYLE>

<DIV class=Section1>
<P class=MsoNormal>So were we able to come up with a solution to challenge 8? Good question. As it turns out, we wrote the first half of our solution, then put it to the test, just to make sure everything was working correctly. When we did so, we discovered that not only was the code working, but the computer was able to guess the animal we were thinking of, too. (Yes, we know: spooky.) We tried it a few more times (10 or 11, to be a little more precise) and each time the computer was able to guess the animal. At that point we decided that our subroutine wasn’t half-finished after all; instead it was <I>completely</I> finished.</P>
<P class=MsoNormal>So does that mean that the subroutine is guaranteed to guess the correct animal each and every time you play the game? Well, we aren’t willing to go <I>that</I> far. But thanks in part to the fact that we have a relatively small number of animals in our database, it was good enough for us.</P>
<P class=MsoNormal><B>Note</B>. If we really <I>do</I> have a relatively small number of animals in our database shouldn’t we have added <I>more</I> animals to that database? In answer to your question: no. After we committed ourselves to this challenge we only <I>then</I> went searching for a database of animal facts. When that search came up empty, that meant we had to create this database by hand. When you’re creating a database like this by hand, suddenly 71 animals seems like a <I>huge</I> amount.</P>
<P class=MsoNormal>Incidentally, if you’ve spent the past two weeks thinking, “Those OfficePalooza guys are so lazy; I bet they wouldn’t even create a database of animal facts by hand,” well, you were wrong. Not about us being lazy, mind you. But at least we <I>did</I> create a database of animal facts by hand.</P>
<P class=MsoNormal>So what solution did we come up, or half come up with? This one:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Private Sub Command8_Click()</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Set objDatabase = CurrentDb()</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Set objTable = objDatabase.CreateTableDef("WorkingTable")</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objTable.Fields.Append objTable.CreateField("ID", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objTable.Fields.Append objTable.CreateField("Name", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objTable.Fields.Append objTable.CreateField("Type", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objTable.Fields.Append objTable.CreateField("Diet", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objTable.Fields.Append objTable.CreateField("Nocturnal", dbBoolean)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objTable.Fields.Append objTable.CreateField("Lifespan", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objTable.Fields.Append objTable.CreateField("Weight", dbDouble)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objTable.Fields.Append objTable.CreateField("Group", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objTable.Fields.Append objTable.CreateField("Protection", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objTable.Fields.Append objTable.CreateField("Gestation", dbDouble)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objDatabase.TableDefs.Append objTable</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objDatabase.Execute ("INSERT INTO WorkingTable SELECT AnimalFacts.* FROM AnimalFacts;")</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objDatabase.TableDefs("WorkingTable").Fields("Group").Name = "GroupName"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; intAnswer = MsgBox("Is your animal nocturnal?", vbYesNo)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; If intAnswer = vbYes Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where Nocturnal = 0;"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Else</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where Nocturnal &lt;&gt; 0;"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; intAnswer = MsgBox("Does your animal have a group name?", vbYesNo)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; If intAnswer = vbYes Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where GroupName Is Null;"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Else</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where GroupName Is Not Null;"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; intAnswer = MsgBox("Is your animal threatened, endangered, or protected?", vbYesNo)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; If intAnswer = vbYes Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where Protection Is Null;"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Else</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where Protection Is Not Null;"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; intAnswer = MsgBox("Is your animal a carnivore?", vbYesNo)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; If intAnswer = vbYes Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where Diet &lt;&gt; 'Carnivore';"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Else</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where Diet = 'Carnivore'"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><A class="" title=OLE_LINK2 name=OLE_LINK2></A><A class="" title=OLE_LINK1 name=OLE_LINK1></A><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = i + 1</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intAnswer = MsgBox("Is your animal an omnivore?", vbYesNo)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If intAnswer = vbYes Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where Diet &lt;&gt; 'Omnivore';"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where Diet = 'Omnivore';"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; intAnswer = MsgBox("Is your animal a mammal?", vbYesNo)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; If intAnswer = vbYes Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where Type &lt;&gt; 'Mammal';"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Else</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where Type = 'Mammal';"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; intQuestionsLeft = 15 - i</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Set objTempTable = objDatabase.OpenRecordset("WorkingTable", dbOpenDynaset)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; intRecordCount = objTempTable.RecordCount</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objTempTable.Close</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; If intRecordCount &lt; intQuestionsLeft Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set objRecordset = objDatabase.OpenRecordset("WorkingTable")</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objRecordset.MoveFirst</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Do Until objRecordset.EOF</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intAnswer = MsgBox("Is your animal the " &amp; objRecordset.Fields("Name"), vbYesNo)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If intAnswer = vbYes Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "I win!"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objRecordset.Close</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objDatabase.TableDefs.Delete "WorkingTable"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objRecordset.MoveNext</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Loop</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp; End If</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; MsgBox "I give up; you win!"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objRecordset.Close</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objDatabase.TableDefs.Delete "WorkingTable"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objDatabase.Close</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">End Sub</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>As for how this code works, well, let’s see if we can figure that out. As you can see, we start out simple enough, using this line of code to create an object reference to the current database (Experienced_challenge_8.accdb):</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">Set objDatabase = CurrentDb()</SPAN></P>
<P class=MsoNormal>After that simple and straightforward opening we then run smack dab into <I>this</I> line of code:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">Set objTable = objDatabase.CreateTableDef("WorkingTable")</SPAN></P>
<P class=MsoNormal>What’s going on here? Well, there are a number of different ways we could approach this issue. (In fact, nearly everyone who submitted a solution for challenge 8 attacked the problem from a slightly different angle.) Because we <I>did</I> have a relatively small database to work with, we decided that the easiest solution (and for some of us, the easiest solution is almost always the best solution) was to make a copy of the AnimalFacts table, ask a question, and then, based on the answer to that question, delete the appropriate animals from the copied table. For example, suppose we ask, “Is your animal a mammal?” If the answer is yes, then we’d delete all the animals in the copied table that are <I>not</I> mammals. If the answer is no, then we’d delete all the animals in the copied table that <I>are</I> mammals. After we ask enough questions we’ll eventually have just one animal left in the copied table: the animal you were thinking of.</P>
<P class=MsoNormal><B>Note</B>. Or at least that was the plan. As you’ll see, though, we ended up taking a bit of a shortcut in the subroutine we actually wrote.</P>
<P class=MsoNormal>So how do we make a copy of the table AnimalFacts? Well, as far as we know, there’s no straightforward way to copy a table in Access. Therefore, we need to create the new table (which means specifying all the fields for the table) and then copy the data from AnimalFacts to our new table (which we christened “WorkingTable”). The <B>CreateTableDef</B> method simply creates a workspace of sorts where we can define the new table and all its fields.</P>
<P class=MsoNormal>Which just happens to be what this chunk of code does:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objTable.Fields.Append objTable.CreateField("ID", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objTable.Fields.Append objTable.CreateField("Name", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objTable.Fields.Append objTable.CreateField("Type", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objTable.Fields.Append objTable.CreateField("Diet", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objTable.Fields.Append objTable.CreateField("Nocturnal", dbBoolean)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objTable.Fields.Append objTable.CreateField("Lifespan", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objTable.Fields.Append objTable.CreateField("Weight", dbDouble)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objTable.Fields.Append objTable.CreateField("Group", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objTable.Fields.Append objTable.CreateField("Protection", dbText)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objTable.Fields.Append objTable.CreateField("Gestation", dbDouble)</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>All we’re doing here is recreating all the fields found in the AnimalFacts table. To do that, we use the <B>CreateField</B> method to specify a new field for our table. As you can see, CreateField takes two parameters: the field name (e.g., <B>ID</B>) and the datatype for the field (e.g., <B>dbText</B>, a constant that creates a field for storing string values). After defining the new field we then use the <B>Append</B> method to tack this new field onto the <B>Fields</B> collection of the WorkingTable table.</P>
<P class=MsoNormal>See how that works? And so why do we show 10 lines of code above? You got it: because the AnimalFacts table has 10 fields, and we want WorkingTable to replicate the structure of the AnimalFacts table.</P>
<P class=MsoNormal>After we’ve defined all the fields we can then <B>Append</B> the new table to the database:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objDatabase.TableDefs.Append objTable</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>At this point we have a new table – WorkingTable – that replicates the <I>structure</I> of the AnimalFacts table. However, there isn’t any actual data in WorkingTable. Our next line of code is designed to fix that problem:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objDatabase.Execute ("INSERT INTO WorkingTable SELECT AnimalFacts.* FROM AnimalFacts;")</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>This is just good old-fashioned SQL: the <B>INSERT INTO</B> query enables us to copy all the data from AnimalFacts and insert that data into WorkingTable. And because we’ve been careful to ensure that the field names (and field datatypes) are identical between the two tables that means that, for all intents and purposes, WorkingTable is now an exact duplicate of AnimalFacts.</P>
<P class=MsoNormal>But, uh, not for long. This might be difficult for you to believe, but we goofed when we created the AnimalFacts table. We named one of our fields <B>Group</B>, which we shouldn’t have done. (Why not? Because <I>Group</I> is a reserved word in the SQL query language, which meant we immediately ran into problems when we tried using the field name <I>Group</I> in our SQL queries.) Fortunately there’s an easy fix to the problem (when you make as many mistakes as we do you get pretty good at fixing problems). This line of code simply renames <I>Group</I> to <I>GroupName</I>:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">objDatabase.TableDefs("WorkingTable").Fields("Group").Name = "GroupName"</SPAN></P>
<P class=MsoNormal>Now why didn’t we think of that in the first place?</P>
<P class=MsoNormal>At this point, we’re ready to start playing Twenty Questions. As we noted earlier, the approach we decided upon relies on us asking a question, deleting the appropriate records from WorkingTable, then repeating the process until we either have exceeded the 20 allowed questions or until we’ve guessed the animal we’re thinking of. With that in mind, the first question we ask is this: Is your animal nocturnal? The code for handling this question, and the response, is shown below:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">intAnswer = MsgBox("Is your animal nocturnal?", vbYesNo)</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">If intAnswer = vbYes Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where Nocturnal = 0;"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Else</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objDatabase.Execute "DELETE * FROM WorkingTable Where Nocturnal &lt;&gt; 0;"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">End If</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>As you can see, in the first line we’re simply using the <B>MsgBox</B> function to ask whether or not the animal is nocturnal. In addition to specifying the text of the question we also tacked on the constant <B>vbYesNo</B>; this adds <B>Yes</B> and <B>No</B> button to the resulting message box. We don’t just display that message box; we also grab the value of the button that was clicked (<B>Yes</B> or <B>No</B>) and stash it in the variable intAnswer.</P>
<P class=MsoNormal>And what do we do with the variable intAnswer? Well, for starters, we check to see if you clicked <B>Yes</B>; if so, then intAnswer will be equal to the constant <B>vbYes</B>:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">If intAnswer = vbYes Then</SPAN> </P>
<P class=MsoNormal>Let’s say that you <I>did</I> click <B>Yes</B>. That can mean only one thing: the animal you’re thinking of must be nocturnal. If that’s the case, then we use this line of code (and a SQL <B>DELETE</B> query) to delete all the records from WorkingTable where the <B>Nocturnal</B> field is equal to 0. (When we copy the data over, the <I>No</I> values in the Nocturnal field get copied over as 0’s and the <I>Yes</I> values get copied over as -1’s.) That’s what this line of code is for:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">objDatabase.Execute "DELETE * FROM WorkingTable Where Nocturnal = 0;"</SPAN></P>
<P class=MsoNormal>If intAnswer is not equal to vbYes then we delete all the record where Nocturnal is <I>not</I> equal to 0:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">objDatabase.Execute "DELETE * FROM WorkingTable Where Nocturnal &lt;&gt; 0;"</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>Needless to say, nothing too fancy there.</P>
<P class=MsoNormal>Incidentally, we didn’t arbitrarily choose to start with the question “Is your animal nocturnal?” Instead, that was a calculated decision on our part. If you thumb through the AnimalFacts table (which would have been a good thing to do before you started writing your code) you would have noticed that there are only a handful of nocturnal animals. That’s why we started with this question: if the animal you were thinking of <I>is</I> nocturnal then we’ve pretty much won the game at this point.</P>
<P class=MsoNormal><B>Note</B>. Why have we pretty much won the game at this point? Well, there are only 6 or 7 nocturnal animals in the database. We get 20 questions and we’ve asked 1; that means we still have 19 questions available to us, and only 6 or 7 possible animals that meet the description of the target animal. At this point we can simply start guessing animal names and be assured that we’ll get the answer right before we run out of questions.</P>
<P class=MsoNormal>After asking whether the animal is nocturnal we then ask whether the animal has a group name; whether the animal is threatened, endangered, or protected; and whether or not the animal is a carnivore. (And, if the animal is <I>not</I> a carnivore, then we ask if it happens to be an omnivore. With those two questions we can then determine whether we are dealing with a carnivore, an omnivore, or an herbivore.) Finally, we ask whether or not the animal is a mammal. Each time we ask a question, and each time we get back a yes or no, we delete the appropriate records from WorkingTable.</P>
<P class=MsoNormal>That brings us to this block of code:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">intQuestionsLeft = 15 - i</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Set objTempTable = objDatabase.OpenRecordset("WorkingTable")</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">intRecordCount = objTempTable.RecordCount</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objTempTable.Close</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>What are we doing here? We’re glad you asked that question. In the first line, we’re simply determining how many questions we have left. We’ve asked at least 5, and possibly 6 if we had to ask if the animal is an omnivore. If we <I>did</I> ask the omnivore question then the counter variable i will be equal to 1; otherwise that counter variable will be equal to 0. We simply subtract the value of i from 15 to determine the number of questions remaining to us.</P>
<P class=MsoNormal>So we now have 15 (or possibly 14) questions left. Our next chore (which happens to encompass the next four lines of code) determines the number of animals (records) left in WorkingTable. As it turns out, Access has a somewhat annoying habit of reporting a record count different from the count you might expect. When you open a table you get back the number of records in that table. However, if you open a recordset using a query (e.g., “Select * From WorkingTable”) you back the number of records that were accessed. That’s always going to be 1 the first time you open that recordset. In other words, Access will always tell you that you have 1 record in the recordset. That’s really not all that helpful.</P>
<P class=MsoNormal>Because of that, we have to use a slightly-different route to determine the number of records in the table. We start out by using the <B>OpenRecordset</B> method to directly open the table WorkingTable. After the table is open we can then grab the RecordCount, stash the value in the variable intRecordCount, and then close the table.</P>
<P class=MsoNormal>So why do we need the record count anyway? Well, what we’re doing here is seeing if we have more questions left than we do animals. Just like with the question “Is your animal nocturnal?” if we have 15 questions left and there are just 11 animals left in WorkingTable, well, we’ve won; all we have to do is loop through the animals still remaining in WorkingTable until we guess the correct animal.</P>
<P class=MsoNormal>And just how do we do <I>that</I>? Well, for starters we reopen the table WorkingTable and then move the cursor to the first record in the resulting recordset. That’s what these two lines of code are for:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Set objRecordset = objDatabase.OpenRecordset("WorkingTable")</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objRecordset.MoveFirst</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>As soon as we’ve done that we set up a Do Until loop that will continue to run until we reach the end of the recordset:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">Do Until objRecordset.EOF</SPAN></P>
<P class=MsoNormal>Inside this loop we use this line of code to guess the animal in question; to make sure you know which animal we’re talking about, we use the value of the <B>Name</B> field in our question:</P>
<P class=MsoNormal><SPAN style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'">intAnswer = MsgBox("Is your animal the " &amp; objRecordset.Fields("Name"), vbYesNo)</SPAN></P>
<P class=MsoNormal>If you answer <B>No</B> then we call the <B>MoveNext</B> record to move to the next record in the recordset and then try again. If you answer <B>Yes</B>, however, we run this block of code instead:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">If intAnswer = vbYes Then</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; MsgBox "I win!"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objRecordset.Close</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; objDatabase.TableDefs.Delete "WorkingTable"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; Exit Sub</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">End If</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>Here we simply echo back the fact that the computer won and then close the recordset. After that we use the <B>Delete</B> method to delete WorkingTable from the database, then use <B>Exit Sub</B> to exit the subroutine. </P>
<P class=MsoNormal>This, by the way, is the block of code we expected to use later in the script, after we had asked a few more questions. However, the first few times we tested the subroutine we found out that we didn’t <I>have</I> to ask any more questions: we always had fewer animals left in the table than we had questions remaining to ask. Does that mean that this subroutine will <I>always</I> win, considering the small number of animals in the database? Well, we can’t say that for sure. But it <I>will</I> win far more often than it will lose.</P>
<P class=MsoNormal>Which is a heck of a lot better than we <I>usually</I> do!</P>
<P class=MsoNormal>But what happens if we <I>do</I> have more animals in the table than we have questions remaining? Well, originally our intention was to ask a few more questions (e.g., “Does your animal weigh 100 pounds or more?”). Because we kept winning all the time, however, we decided to forego those additional questions. Instead, if we end up with more animals than questions we do what most people would do when faced with a difficult situation: we give up. Here’s the block of “I surrender” code that runs in that case:</P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">MsgBox "I give up; you win!"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">&nbsp;&nbsp;&nbsp; </SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objRecordset.Close</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objDatabase.TableDefs.Delete "WorkingTable"</SPAN></P>
<P class=MsoNormal style="MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal"><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">objDatabase.Close</SPAN></P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal>So is that taking the easy way out? Of course it is; would have expected anything <I>other</I> than that?</P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal mce_keep="true">&nbsp;</P>
<P class=MsoNormal mce_keep="true">&nbsp;</P></DIV>]]></content:encoded>
    </item>
  </channel>
</rss>