<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Techamajig</title>
        <link>http://blogs.sftsrc.com/johng/Default.aspx</link>
        <description>"Use the ceremonial techamajig!"</description>
        <language>en-US</language>
        <copyright>John Goalby</copyright>
        <generator>Subtext Version 2.1.1.1</generator>
        <image>
            <title>Techamajig</title>
            <url>http://blogs.sftsrc.com/images/RSS2Image.gif</url>
            <link>http://blogs.sftsrc.com/johng/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>Creating a Gradient Brush Using a Color Resource</title>
            <category>WPF</category>
            <link>http://blogs.sftsrc.com/johng/archive/2007/09/12/49.aspx</link>
            <description>&lt;p&gt;I have been playing with the Blend August Preview and in particular the resource feature.  This is an excellent feature that allows you to style your user interface from a single location much like CSS does for web pages. &lt;/p&gt;
&lt;p&gt;I created a new project.  I added a rectangle to the window and changed its color to a nice shade of blue: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/091207_2208_CreatingaGr1.png" /&gt; 	&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;I created another rectangle next to the original rectangle and removed the stroke from both of them: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/091207_2208_CreatingaGr2.png" /&gt; 	&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;Clicking on the original rectangle, I converted the color to a resource named MyColor and put it in a new resource dictionary: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/091207_2208_CreatingaGr3.png" /&gt; 	&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/091207_2208_CreatingaGr4.png" /&gt; 	&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;Now, when I change MyColor in the resource dictionary, all instances of MyColor will change with it: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/091207_2208_CreatingaGr5.png" /&gt; 	&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;So far, so good.  I would now like my second rectangle to be a linear gradient going from MyColor to black.  When I change MyColor I want it to change the initial gradient color too. &lt;/p&gt;
&lt;p&gt;Unfortunately, there doesn't seem to be a way to do this in the GUI.  Fortunately, there is a very simple way to do this in the XAML. &lt;/p&gt;
&lt;p&gt;Click on the second rectangle and change its fill to a gradient.  Change the first gradient color to red and the second gradient color to black: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/091207_2208_CreatingaGr6.png" /&gt; 	&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;Now, convert the gradient brush to a resource.  Call it MyBrush and put it in the same resource dictionary. &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/091207_2208_CreatingaGr7.png" /&gt; 	&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;Save all of your files and click on the resource dictionary file.  Open it in XAML view.  You should see the following: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/091207_2208_CreatingaGr8.png" /&gt; 	&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;Change the first gradient stop from "#FFFF0000" (red) to "{DynamicResource MyColor}": &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/091207_2208_CreatingaGr9.png" /&gt; 	&lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;p&gt;Now, when you change MyColor, the first color in the MyBrush resource will also change: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/091207_2208_CreatingaGr10.png" /&gt;&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/johng/aggbug/49.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Goalby</dc:creator>
            <guid>http://blogs.sftsrc.com/johng/archive/2007/09/12/49.aspx</guid>
            <pubDate>Wed, 12 Sep 2007 22:08:31 GMT</pubDate>
            <comments>http://blogs.sftsrc.com/johng/archive/2007/09/12/49.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.sftsrc.com/johng/comments/commentRss/49.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.sftsrc.com/johng/services/trackbacks/49.aspx</trackback:ping>
        </item>
        <item>
            <title>Strangeness with Excel 2007 and Last Modified Date</title>
            <category>Excel 2007</category>
            <link>http://blogs.sftsrc.com/johng/archive/2007/06/02/40.aspx</link>
            <description>&lt;p&gt;I just noticed something very strange when opening an Excel document that is in Excel 97-2003 format. &lt;/p&gt;
&lt;p&gt;This is the file system before I open the file: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/060307_0455_Strangeness1.png" /&gt; &lt;/p&gt;
&lt;p&gt;Then I open the file using Excel 2007. I do nothing to the file. It is opened in compatibility mode. The file system now looks like this: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/060307_0455_Strangeness2.png" /&gt; &lt;/p&gt;
&lt;p&gt;The last modified date changed! As strange as that is, it gets even stranger. Now if I close Excel, I don't get any warnings and the file system now looks like this: &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/060307_0455_Strangeness3.png" /&gt; &lt;/p&gt;
&lt;p&gt;I kid you not! That is a new screenshot, not a copy of the first one! &lt;/p&gt;
&lt;p&gt;Strange!&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/johng/aggbug/40.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Goalby</dc:creator>
            <guid>http://blogs.sftsrc.com/johng/archive/2007/06/02/40.aspx</guid>
            <pubDate>Sun, 03 Jun 2007 04:55:37 GMT</pubDate>
            <comments>http://blogs.sftsrc.com/johng/archive/2007/06/02/40.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.sftsrc.com/johng/comments/commentRss/40.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.sftsrc.com/johng/services/trackbacks/40.aspx</trackback:ping>
        </item>
        <item>
            <title>Using LINQ to access Outlook data - Part 2</title>
            <category>LINQ</category>
            <link>http://blogs.sftsrc.com/johng/archive/2007/05/30/39.aspx</link>
            <description>&lt;p&gt;Please see &lt;a href="http://blogs.sftsrc.com/johng/archive/2007/05/25/Using-LINQ-to-access-Outlook-data.aspx"&gt;this previous post&lt;/a&gt; on how to get started using LINQ with Outlook.  I will assume you have added the appropriate references to the Outlook object model.
&lt;/p&gt;&lt;p&gt;In this post I am going to show you how to find emails from people that you don't have in your address book.  We will achieve this by cross referencing the information in your contacts with the emails in your inbox.
&lt;/p&gt;&lt;p&gt;Now, inside the Main method, we need to add the following code:
&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;Outlook.&lt;span style="color:#2b91af"&gt;_Application&lt;/span&gt; outlookObject = &lt;span style="color:blue"&gt;new&lt;/span&gt; Outlook.&lt;span style="color:#2b91af"&gt;Application&lt;/span&gt;();&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;This code references the Outlook application.  We now need to specify which Outlook folders we wish to use:
&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;Outlook.&lt;span style="color:#2b91af"&gt;MAPIFolder&lt;/span&gt; contactsFolder = outlookObject.ActiveExplorer().Session.GetDefaultFolder(Outlook.&lt;span style="color:#2b91af"&gt;OlDefaultFolders&lt;/span&gt;.olFolderContacts);&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;Outlook.&lt;span style="color:#2b91af"&gt;MAPIFolder&lt;/span&gt; inboxfolder = outlookObject.ActiveExplorer().Session.GetDefaultFolder(Outlook.&lt;span style="color:#2b91af"&gt;OlDefaultFolders&lt;/span&gt;.olFolderInbox);&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;The email addresses for contacts are contained in the Email1Address, Email2Address and Email3Address.  These are three separate properties on a contact.  We can get that information like so:
&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;var&lt;/span&gt; contactsEmail = &lt;span style="color:blue"&gt;from&lt;/span&gt; contact &lt;span style="color:blue"&gt;in&lt;/span&gt; contactsFolder.Items.OfType&amp;lt;Outlook.&lt;span style="color:#2b91af"&gt;ContactItem&lt;/span&gt;&amp;gt;()
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:10pt"&gt;
			&lt;span style="color:blue"&gt;select&lt;/span&gt;
			&lt;span style="color:blue"&gt;new&lt;/span&gt;
			&lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:blue"&gt;string&lt;/span&gt;&amp;gt;() { contact.Email1Address, contact.Email2Address, contact.Email3Address };&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;This will give us a collection of a list of email addresses.  Each contact may have up to three email addresses specified.  This means that the list may contain null entries.  In addition it is not very useful to have an embedded collection.  If we kept it this way we would have to have two foreach loops to iterate through the data.  Fortunately, LINQ provides the SelectMany operator:
&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;var&lt;/span&gt; allContactEmails = contactsEmail.SelectMany(sel =&amp;gt; sel.Where(e =&amp;gt; e != &lt;span style="color:blue"&gt;null&lt;/span&gt;));&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;This single line of code transforms the collection of lists into a single collection of strings with no null entries.  To help us compare the email addresses we now convert them to lower case using the Select operator and remove duplicates with the Distinct operator.  Note that we could have done that on the previous line after the Where:
&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;var&lt;/span&gt; allContactEmailsLower = allContactEmails.Select(sel =&amp;gt; sel.ToLower()).Distinct();&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;Now, let's get the sender's email address from each email in the inbox:
&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;var&lt;/span&gt; emailItems = (&lt;span style="color:blue"&gt;from&lt;/span&gt; email &lt;span style="color:blue"&gt;in&lt;/span&gt; inboxfolder.Items.OfType&amp;lt;Outlook.&lt;span style="color:#2b91af"&gt;MailItem&lt;/span&gt;&amp;gt;()&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;where&lt;/span&gt; email.SenderEmailType == &lt;span style="color:#a31515"&gt;"SMTP"&lt;/span&gt;&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;select&lt;/span&gt; email.SenderEmailAddress.ToLower()).Distinct();&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;We now have a collection of sender email addresses and a collection of email addresses from our address book.  We would like to find out the email addresses that are in the senders list but not in our address book.  We do that with the Except operator:
&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;var&lt;/span&gt; exceptions = emailItems.Except(allContactEmails);&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;The Except operator will return items in the first sequence that are not in the second.  All that is left is to output our results:
&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:blue"&gt;foreach&lt;/span&gt; (&lt;span style="color:blue"&gt;string&lt;/span&gt; str &lt;span style="color:blue"&gt;in&lt;/span&gt; exceptions)&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;{&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;&lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515"&gt;"{0}"&lt;/span&gt;, str);&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;
		&lt;span style="font-family:Courier New; font-size:10pt"&gt;}&lt;/span&gt;
	&lt;/p&gt;&lt;p&gt;That's all there is to it.  Now you can keep your address book up to date.  It would be relatively trivial to update the program to update your address book &lt;span style="font-family:Wingdings"&gt;J&lt;/span&gt;&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/johng/aggbug/39.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Goalby</dc:creator>
            <guid>http://blogs.sftsrc.com/johng/archive/2007/05/30/39.aspx</guid>
            <pubDate>Wed, 30 May 2007 21:52:36 GMT</pubDate>
            <comments>http://blogs.sftsrc.com/johng/archive/2007/05/30/39.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.sftsrc.com/johng/comments/commentRss/39.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.sftsrc.com/johng/services/trackbacks/39.aspx</trackback:ping>
        </item>
        <item>
            <title>SvcHost frustrations, Zooming, and Microsoft Surface</title>
            <link>http://blogs.sftsrc.com/johng/archive/2007/05/30/38.aspx</link>
            <description>&lt;p&gt;As part of my job I am required to connect to a third party VPN.  The security on that network requires, among other things, all major updates.  So, when I tried to login today and could not I decided to force an update.  That update took me 3 hours in all.  The reason being that SvcHost decided to hog my computer.  Steadily mocking me at 99% CPU utilization.
&lt;/p&gt;&lt;p&gt;After some head banging I decided to try out my support options.  Google was my first stop.  I found &lt;a href="http://www.somelifeblog.com/2007/05/windows-xp-svchostexe-100-cpu-high.html"&gt;this site&lt;/a&gt;.  A very handy description about how to solve this "rare" problem where SvcHost pegs your CPU and Windows Update never gets anywhere.  Worked like a charm for me.  Thank you Ken!
&lt;/p&gt;&lt;p&gt;This also gave me a chance to browse the web a little.  A dangerous prospect as it can be hours before I resurface, trying to recall what I was doing in the first place.  I came across two things of note.
&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:14pt"&gt;&lt;strong&gt;ZoomIt
&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;The &lt;a href="http://www.microsoft.com/technet/sysinternals/utilities/zoomit.mspx"&gt;ZoomIt utility&lt;/a&gt; from the sysinternals folks.  Excellent utility for when you give presentations.  A feature I particularly like is being able to wipe the screen blank and write text on it.
&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:14pt"&gt;&lt;strong&gt;Microsoft Surface
&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;The other site I came across was &lt;a href="http://www.microsoft.com/surface/"&gt;Microsoft Surface&lt;/a&gt;.  Wow!  I want one now!  I do think they missed the boat a little with respect to Silverlight.  Why not have 2 demonstrations?  One done in Flash and another done with fancy interaction in Silverlight?  
&lt;/p&gt;&lt;p&gt;I like the idea of rotating photos, but seriously, can Microsoft Surface not detect where you are and orient the photos correctly the first time?
&lt;/p&gt;&lt;p&gt;The drink demo with the bubbles was neat.  What about the Surface detecting you are close to the end of your drink and asking if you would like another?
&lt;/p&gt;&lt;p&gt;What about games?  It would be cool to see a poker demo complete with digital playing cards and virtual chips.
&lt;/p&gt;&lt;p&gt;I would also have liked to see integrated fingerprint/retina reading in the demo.  That way, I would not feel so hesitant about putting my PDA or my credit card on one of these Surfaces.  
&lt;/p&gt;&lt;p&gt;Lastly, this opens up a whole new class of exploits.  I love the idea of hacking my way to free desert at a restaurant!  Yummmy! &lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/johng/aggbug/38.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Goalby</dc:creator>
            <guid>http://blogs.sftsrc.com/johng/archive/2007/05/30/38.aspx</guid>
            <pubDate>Wed, 30 May 2007 18:24:53 GMT</pubDate>
            <comments>http://blogs.sftsrc.com/johng/archive/2007/05/30/38.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.sftsrc.com/johng/comments/commentRss/38.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.sftsrc.com/johng/services/trackbacks/38.aspx</trackback:ping>
        </item>
        <item>
            <title>Freezing Your Drives</title>
            <link>http://blogs.sftsrc.com/johng/archive/2007/05/25/36.aspx</link>
            <description>&lt;p&gt;Check out &lt;a href="http://www.technologyreview.com/blog/garfinkel/17609/"&gt;this article&lt;/a&gt; on using a freezer to recover data off broken hard drives.  I wonder if the freezer can also fix broken code?&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/johng/aggbug/36.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Goalby</dc:creator>
            <guid>http://blogs.sftsrc.com/johng/archive/2007/05/25/36.aspx</guid>
            <pubDate>Sat, 26 May 2007 04:27:08 GMT</pubDate>
            <comments>http://blogs.sftsrc.com/johng/archive/2007/05/25/36.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.sftsrc.com/johng/comments/commentRss/36.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.sftsrc.com/johng/services/trackbacks/36.aspx</trackback:ping>
        </item>
        <item>
            <title>Using LINQ to access Outlook data</title>
            <category>LINQ</category>
            <link>http://blogs.sftsrc.com/johng/archive/2007/05/25/35.aspx</link>
            <description>&lt;p&gt;Grab yourself a &lt;a href="http://msdn2.microsoft.com/en-us/vstudio/aa700831.aspx"&gt;copy&lt;/a&gt; of Visual Studio code name "Orcas" and follow along as we create a program to access your data in Outlook. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 14pt"&gt;&lt;strong&gt;Test Data &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;You will need to have some contacts in Outlook to test this program. Add at least 3 contacts, one with a home phone but no email, one with an email but no phone numbers, and one with no email and no phone numbers. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 14pt"&gt;&lt;strong&gt;Getting Started &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Start "Orcas" and click File-&amp;gt;New-&amp;gt;Project… Choose to create a Console Application in C# with the .NET Framework 3.5. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/052607_0027_UsingLINQto1.png" /&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;We need to add a reference to Outlook 2007. Right click on references in Solution Explorer and choose Add Reference… &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/052607_0027_UsingLINQto2.png" /&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Select the COM tab and choose the Microsoft Outlook 12.0 Object Library and press OK. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/052607_0027_UsingLINQto3.png" /&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Two references will be added. Microsoft.Office.Core and Microsoft.Office.Interop.Outlook. Now add the following using statement to your Program.cs source file: &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; Outlook = Microsoft.Office.Interop.Outlook; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;We now need to get an instance of the Outlook Application object. Type the following code in the Main method: &lt;/p&gt;
&lt;p&gt;    &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;Outlook.&lt;span style="COLOR: #2b91af"&gt;_Application&lt;/span&gt; outlookObject = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; Outlook.&lt;span style="COLOR: #2b91af"&gt;Application&lt;/span&gt;(); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;We want to look at the contacts stored in Outlook so we now get the contacts folder: &lt;/p&gt;
&lt;p&gt;    &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;Outlook.&lt;span style="COLOR: #2b91af"&gt;MAPIFolder&lt;/span&gt; folder = outlookObject.ActiveExplorer().Session.GetDefaultFolder(Outlook.&lt;span style="COLOR: #2b91af"&gt;OlDefaultFolders&lt;/span&gt;.olFolderContacts); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Now, let's define our LINQ query: &lt;/p&gt;
&lt;p&gt;    &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; contactsNoEmail = &lt;span style="COLOR: blue"&gt;from&lt;/span&gt; contact &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; folder.Items &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;where&lt;/span&gt; contact.Email1Address == &lt;span style="COLOR: blue"&gt;null &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;select&lt;/span&gt; contact; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This query is going to get the contacts from the contacts folder where the Email1Address is not defined. Now we need to iterate through our results: &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (Outlook.&lt;span style="COLOR: #2b91af"&gt;ContactItem&lt;/span&gt; contact &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; contactsNoEmail) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;    &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="COLOR: #a31515"&gt;"{0} - {1} {2}"&lt;/span&gt;, contact.LastFirstNoSpaceCompany, contact.FirstName, contact.LastName); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;}&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;Lastly let's output that we have finished in case we get no results. Also we will request that the user press Enter so we can see our results when we run from the debugger: &lt;/p&gt;
&lt;p&gt;    &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="COLOR: #a31515"&gt;"The end"&lt;/span&gt;); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;    &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.ReadLine();&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;Now we need to build our project. Bo to the Build menu and choose Build Solution. The build should fail with the following error: &lt;/p&gt;
&lt;p&gt;&lt;span style="COLOR: red"&gt;The type arguments for method 'System.Linq.Queryable.Where&amp;lt;TSource&amp;gt;(System.Linq.IQueryable&amp;lt;TSource&amp;gt;, System.Linq.Expressions.Expression&amp;lt;System.Linq.Func&amp;lt;TSource,bool&amp;gt;&amp;gt;)' cannot be inferred from the usage. Try specifying the type arguments explicitly. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;To fix this we need to specify the type of the items in the folders Items collection. Change the first line of the LINQ query to: &lt;/p&gt;
&lt;p&gt;    &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; contactsNoEmail = &lt;span style="COLOR: blue"&gt;from&lt;/span&gt; contact &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; folder.Items&lt;strong&gt;.OfType&amp;lt;Outlook.&lt;span style="COLOR: #2b91af"&gt;ContactItem&lt;/span&gt;&amp;gt;()&lt;/strong&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;Now you should be able to build and run the program. When you run your program you may get a warning dialog. Choose to allow access if this is in response to your program running. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/052607_0027_UsingLINQto4.png" /&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;You should see a list of contacts who don't have an Email1Address defined followed by the string "The End". You will need to press Enter to end the program. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 14pt"&gt;&lt;strong&gt;Adding a Second Query &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Now, let's make our program a little more useful. It is possible that we have contacts with phone numbers but no email address. If we have a contact without either we want to know. We could do this in the same query, but for demonstration purposes we are going to do it as a second query. Add the following query after the first query inside your Main function: &lt;/p&gt;
&lt;p&gt;    &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; contactsNoPhone = &lt;span style="COLOR: blue"&gt;from&lt;/span&gt; contact &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; folder.Items.OfType&amp;lt;Outlook.&lt;span style="COLOR: #2b91af"&gt;ContactItem&lt;/span&gt;&amp;gt;() &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;        &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; (contact.HomeTelephoneNumber == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;) &amp;amp;&amp;amp; (contact.BusinessTelephoneNumber == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;) &amp;amp;&amp;amp; (contact.MobileTelephoneNumber == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;        &lt;span style="COLOR: blue"&gt;select&lt;/span&gt; contact;&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;We check to see if the contact has a home, business or mobile number defined. If they don't we return that contact to the contactsNoPhone collection. To see the results of the second query we can change our iteration loop as follows: &lt;/p&gt;
&lt;p&gt;    &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (Outlook.&lt;span style="COLOR: #2b91af"&gt;ContactItem&lt;/span&gt; contact &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; &lt;strong&gt;contactsNoPhone&lt;/strong&gt;) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;When we build and run the program we get a list of contacts that don't have a home, business or mobile number defined in the contact information. &lt;/p&gt;
&lt;p&gt;The next step is to combine the two queries so that we can find contacts without a phone and without an email address. To do this we are going to intersect the two queries giving us only the contacts that are in both queries and changing the iteration to use the new variable: &lt;/p&gt;
&lt;p&gt;    &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; intersection = contactsNoEmail.Intersect(contactsNoPhone); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (Outlook.&lt;span style="COLOR: #2b91af"&gt;ContactItem&lt;/span&gt; contact &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; &lt;strong&gt;intersection&lt;/strong&gt;)&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;Build the program and run it. You will notice that you have no contacts listed even though you added some contacts that should match the query. The reason is that each query of Outlook returns new objects such that when they are compared, they appear different. This is due to there being a reference comparison rather than a value comparison. We can fix this with a couple of simple changes. &lt;/p&gt;
&lt;p&gt;First we need to define a new class that implements IEqualityComparer for Outlook.ContactItem's. This class looks like this: &lt;/p&gt;
&lt;p&gt;    &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ContactItemComparer&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;IEqualityComparer&lt;/span&gt;&amp;lt;Outlook.&lt;span style="COLOR: #2b91af"&gt;ContactItem&lt;/span&gt;&amp;gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;    { &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;        &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; Equals(Outlook.&lt;span style="COLOR: #2b91af"&gt;ContactItem&lt;/span&gt; a, Outlook.&lt;span style="COLOR: #2b91af"&gt;ContactItem&lt;/span&gt; b) &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 72pt"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;return&lt;/span&gt; (a.LastFirstNoSpaceCompany == b.LastFirstNoSpaceCompany); &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;} &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; GetHashCode(Outlook.&lt;span style="COLOR: #2b91af"&gt;ContactItem&lt;/span&gt; a) &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier New"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;    return&lt;/span&gt; a.Size; &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN-LEFT: 36pt"&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;} &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;}&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;This defines an Equals and a GetHashCode function. Note that these are by no means industrial strength implementations as they only compare the LastFirstNameNoSpaceCompany field and uses the size of the contact item as the hash. This will suffice for our example although checks for null will have to be done in production code. All that leaves is for us to specify the ContactItemComparer in the intersect function: &lt;/p&gt;
&lt;p&gt;    &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; intersection = contactsNoEmail.Intersect(contactsNoPhone&lt;strong&gt;, &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ContactItemComparer&lt;/span&gt;()&lt;/strong&gt;); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;When you now build and run your program you should see contacts that have no email in addition to no home, business or mobile phone number specified. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 14pt"&gt;&lt;strong&gt;Summary &lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This example shows how easy it is to access the Outlook object model from LINQ. Although you could write this program without LINQ, the query syntax becomes compelling when you start to use it to access all your data stores.&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/johng/aggbug/35.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Goalby</dc:creator>
            <guid>http://blogs.sftsrc.com/johng/archive/2007/05/25/35.aspx</guid>
            <pubDate>Sat, 26 May 2007 00:28:12 GMT</pubDate>
            <comments>http://blogs.sftsrc.com/johng/archive/2007/05/25/35.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blogs.sftsrc.com/johng/comments/commentRss/35.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.sftsrc.com/johng/services/trackbacks/35.aspx</trackback:ping>
        </item>
        <item>
            <title>From good to bad</title>
            <link>http://blogs.sftsrc.com/johng/archive/2007/05/18/30.aspx</link>
            <description>&lt;p&gt;Two recent news articles related to computer forensics stood out recently.
&lt;/p&gt;&lt;p&gt;The &lt;a href="http://www.allheadlinenews.com/articles/7007308238"&gt;first article&lt;/a&gt; talks about a Filipino cybersleuth being awarded the world's best computer investigator for 2007.  The winner, Alexander Ramos, has been a cybercrime investigator for 10 years.  The prize of $10,000 goes to the charity of the winners choosing.
&lt;/p&gt;&lt;p&gt;In the &lt;a href="http://www.darkreading.com/document.asp?doc_id=123716&amp;amp;WT.svl=cmpnews1_1"&gt;second article&lt;/a&gt;, a bogus computer expert pleads guilty of falsifying his credentials.  The computer expert faces a maximum of 10 years in prison and a fine of $500,000.
&lt;/p&gt;&lt;p&gt;An interesting comparison of the two ends of computer forensic investigations.&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/johng/aggbug/30.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Goalby</dc:creator>
            <guid>http://blogs.sftsrc.com/johng/archive/2007/05/18/30.aspx</guid>
            <pubDate>Fri, 18 May 2007 17:22:36 GMT</pubDate>
            <comments>http://blogs.sftsrc.com/johng/archive/2007/05/18/30.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blogs.sftsrc.com/johng/comments/commentRss/30.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.sftsrc.com/johng/services/trackbacks/30.aspx</trackback:ping>
        </item>
        <item>
            <title>Previous Versions Part 2</title>
            <category>Windows Vista</category>
            <link>http://blogs.sftsrc.com/johng/archive/2007/05/03/21.aspx</link>
            <description>&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"&gt;In my first blog post on Shadow Copy, I said that Previous Versions is available in the Ultimate, Business and Enterprise versions of Vista. This means that the feature is not available in Home and Home Premium versions. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"&gt;It is true, although there is a twist. You don't have the ability to access the Previous Versions of files in Home and Home Premium, but the Previous Versions are still being made. One of the students in my Computer Forensics class pointed out this &lt;a href="http://pcpitstop.com/news/rob/rcheng0704.asp"&gt;article&lt;/a&gt;. The article says that if you upgrade from Home or Home Premium to Ultimate, Business or Enterprise versions of Vista, then you can get access to the Previous Versions of your files. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Arial"&gt;This is great news for the forensic examiner as they have even more evidence to look at and Previous Versions can provide some of the best evidence on a disk.&lt;/span&gt;&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/johng/aggbug/21.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Goalby</dc:creator>
            <guid>http://blogs.sftsrc.com/johng/archive/2007/05/03/21.aspx</guid>
            <pubDate>Thu, 03 May 2007 17:07:51 GMT</pubDate>
            <comments>http://blogs.sftsrc.com/johng/archive/2007/05/03/21.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.sftsrc.com/johng/comments/commentRss/21.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.sftsrc.com/johng/services/trackbacks/21.aspx</trackback:ping>
        </item>
        <item>
            <title>Blogging Using Word 2007 with Subtext</title>
            <link>http://blogs.sftsrc.com/johng/archive/2007/05/02/20.aspx</link>
            <description>&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;I have now been blogging using Word 2007 for a while.  It really makes the blogging process about as painless as it can be.  I don't have to worry about formatting and can include screenshots painlessly in my posts.  Although I haven't done it yet, I also have the ability to create SmartArt and include that in my posts to illustrate a point (or not!):
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/050207_2153_BloggingUsi1.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Setting Word 2007 up for blogging with Subtext is not entirely intuitive and also required a small code change to get image posting to work.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Go to the Office menu, choose Publish and select Blog:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/050207_2153_BloggingUsi2.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;You will be presented with a new Word document that looks like this:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/050207_2153_BloggingUsi3.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;You can title your post by replacing the text "Enter Post Title here".
&lt;/p&gt;&lt;p&gt;To set up Word 2007 to work with Subtext for the first time, you need to click on manage accounts:
&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/050207_2153_BloggingUsi4.png" alt="" /&gt;
	&lt;/p&gt;&lt;p&gt;Click New to create a new account.  You will see the following dialog.  Choose other for blog provider when using Subtext:
&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/050207_2153_BloggingUsi5.png" alt="" /&gt;
	&lt;/p&gt;&lt;p&gt;Then click Next. You will now see a dialog for specifying the blog API.  Choose the following settings:
&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/050207_2153_BloggingUsi6.png" alt="" /&gt;
	&lt;/p&gt;&lt;p&gt;Click on the Picture Options button and make sure the dialog has the following options:
&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/050207_2153_BloggingUsi7.png" alt="" /&gt;
	&lt;/p&gt;&lt;p&gt;&lt;br /&gt;You are now set as far as Word 2007 is concerned.  Posting of pictures will not work until you change Subtext.  The problem stems from a misunderstanding of the MetaWeblog spec by Word 2007.  Word 2007 is sending the blogid as an int rather than a string.  The change we made was to create a duplicate method that took an int and converted it to a string in the call to the other method.  The method is the metaWeblog.newMediaObject.  A quick recompile later and everything works just great!
&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/johng/aggbug/20.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Goalby</dc:creator>
            <guid>http://blogs.sftsrc.com/johng/archive/2007/05/02/20.aspx</guid>
            <pubDate>Wed, 02 May 2007 21:53:18 GMT</pubDate>
            <comments>http://blogs.sftsrc.com/johng/archive/2007/05/02/20.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.sftsrc.com/johng/comments/commentRss/20.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.sftsrc.com/johng/services/trackbacks/20.aspx</trackback:ping>
        </item>
        <item>
            <title>Excel Conditional Formatting</title>
            <category>Excel 2007</category>
            <link>http://blogs.sftsrc.com/johng/archive/2007/04/27/18.aspx</link>
            <description>&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;I recently saw a &lt;a href="http://www.perceptualedge.com/blog/?p=116"&gt;post&lt;/a&gt; on the &lt;a href="http://perceptualedge.com/blog/"&gt;Visual Business Intelligence blog&lt;/a&gt; about representing 360 data points.  The discussion in the forum was interesting as people demonstrated ways to represent these data points on a single image.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;I wanted to see what I could come up with.  Representing information in effective ways is a good skill for the forensic analyst.  I also wanted to try out the conditional formatting feature of Excel 2007 to see what it was capable of.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;First step was to download the &lt;a href="http://bizviz.jorgecamoes.com/wp-content/uploads/howtos/householdexpenditureeu.xls"&gt;data&lt;/a&gt;.  Here is what the spreadsheet looks like:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit1.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Looking at some of the other submissions, I decided to order the columns similarly.  Housing was the biggest expenditure down through education.  This would make the formatting easier to see later.  You also need to do this step first otherwise your formatting may get "confused" when you start moving columns.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;On the Home tab on Excel 2007, there is a conditional formatting button.  Selecting this button gives the following choices:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit2.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;There are some powerful options under this area and I encourage you to experiment with them.  Today I am going to look specifically at Data Bars and Color Scales.
&lt;/span&gt;&lt;/p&gt;&lt;h2&gt;Data Bars
&lt;/h2&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;If I select all of the data and choose the blue Data Bar, I get the following:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit3.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Notice how the bars are relative to the biggest data item in the selection.  If I was to instead select each column individually and assign the blue data bar we would get the following:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit4.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Which style you want comes down to what you are trying to show with your data.  For our purposes, we would like to see the data bars relative to the largest value, so we will use the first method.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;There are some issues with the data bars:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit5.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;First, you will notice that there is a gradient on the data bar.  This can make the end of the data bar hard to see.  Unfortunately, this is not something that can be changed.  
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Second, you may also notice that the smaller values still have a considerable size data bar.  Should the data bar for 0.3 really be that big?  Turns out that the data bar has a minimum size.  Fortunately this can be changed.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;The change can be made by going into the Visual Basic editor (ALT-F11), bringing up the immediate window (CTRL-G) and typing the following:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New"&gt;Range("B2:M31").FormatConditions(1).PercentMin = 1
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;After pressing the enter key, this will change the minimum size of the data bar to its smallest value for the range specified:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit6.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;One thing that would be nice is to have the data bars be different colors depending on their value.  Through the UI there really is no way to do this.  Thanks to the &lt;a href="http://blogs.msdn.com/excel/default.aspx"&gt;Excel 2007 Blog&lt;/a&gt;, there is a &lt;a href="http://blogs.msdn.com/excel/archive/2006/02/24/538875.aspx"&gt;way&lt;/a&gt; to achieve this.  This "trick" uses a little VBA code to achieve its goal.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;With Excel 2007, you can apply multiple data bar conditional formats to the same data, one over the top of the other.  Then, once you have created your multiple data bar layers, you can selectively show the ones you want.  There is a "trick" to the "trick" though.  Each successive data bar format needs to be on a different selection.  This was not explained in the blog entry, but I couldn't find a way to overlay formats on the same data selection.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;So, starting with the original Excel spreadsheet, select all of the data and apply the blue data bar format and then change the PercentMin to 1:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit7.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Now, select all of the data &lt;strong&gt;AND&lt;/strong&gt; an extra column and apply the orange data bar format:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit8.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;The blue data bar format will be underneath the orange.  Now, select all of the data &lt;strong&gt;AND&lt;/strong&gt; 2 extra columns and apply the red data bar format:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit9.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Now we can selectively display the data bars.  Select the data from B3 through M31 – This selects all data except for the EU25 data.  Now bring up the Visual Basic editor and type the following in the immediate window:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;selection.FormatConditions(1).formula = "=if(b3&amp;lt;b$2, true, false)"
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Courier New; font-size:9pt"&gt;selection.FormatConditions(2).formula = "=if(b3=b$2, true, false)"
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:9pt"&gt;&lt;span style="font-family:Courier New"&gt;selection.FormatConditions(3).formula = "=if(b3&amp;gt;b$2, true, false)"&lt;/span&gt;&lt;span style="font-family:Arial"&gt;
			&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Now, each line of VBA code will only be executed when you press enter on that line.  You will therefore need to press enter 3 times to execute each line of VBA code.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;The first line specifies the visibility of the red data bar (the last format added is at index 1).  We specify that the red data bars indicate values less than the EU25 average.  The second line indicates in orange the values equal to the EU25 average.  The third line of code indicates in blue the values greater than the EU25 average.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;You should end up with the following:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit10.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Looking at this you can clearly see that the countries are listed in order of percentage spent on food.  To change it to housing we can sort the data.  To do that, select all of the data except for EU25 (as that cell is used in our formula).  Now click on the Z-A sort button on the Data tab:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit11.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;There appears to be an artifact in the housing column where some red shows up.  We can remove that by executing the 3 lines of VBA code again.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;It is important to note that above I used data bars on the whole data set.  If you wanted the data bars to be specific to an expenditure, you would have to repeat the procedure above for each column.  This is shown in the final chart in the blog.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Now, let's turn our attention over to the Color Scales.
&lt;/span&gt;&lt;/p&gt;&lt;h2&gt;Color Scales
&lt;/h2&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Starting out with the original data, we can select all of the data and apply the Red, Yellow, Blue color scale.  The result will be something like this:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit12.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;You can clearly see that there is more expenditure on housing and less on education.  You can also see that restaurants have quite a range of values and Romania spends a lot more than the other countries on food.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;You can customize the colors using "More Rules…"
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit13.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;There's not really much more to say about color scales, so we will move on to combining the data bar and color scales in the finished spreadsheet.
&lt;/span&gt;&lt;/p&gt;&lt;h2&gt;Finished Spreadsheet
&lt;/h2&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;Here is the finished spreadsheet combining the 2 conditional formatting methods discussed in this post:
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="http://blogs.sftsrc.com/images/blogs_sftsrc_com/johng/042707_2127_ExcelCondit14.png" alt="" /&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;
		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;I chose to use shades of grey for the data bars to prevent clashing with the color scales.  The color scales represent values across the whole data set, whereas the data bars represent values for the particular expenditure.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;In addition, I was able to remove the text for the values.  I did this by making the data values font very big (409pt) and sizing the cells as before.  You then need to align the countries text to the top of the cell.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;The task was to create a single image that had all of the data set represented.  That proves to be quite a challenge.  Typically you would highlight the data you wanted to showcase.
&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Arial; font-size:9pt"&gt;I have posted a better image of the finished spreadsheet to the &lt;a href="http://www.websitetoolbox.com/tool/post/sfew/vpost?id=1811065"&gt;original discussion&lt;/a&gt;.&lt;/span&gt;&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/johng/aggbug/18.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>John Goalby</dc:creator>
            <guid>http://blogs.sftsrc.com/johng/archive/2007/04/27/18.aspx</guid>
            <pubDate>Fri, 27 Apr 2007 21:27:41 GMT</pubDate>
            <comments>http://blogs.sftsrc.com/johng/archive/2007/04/27/18.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.sftsrc.com/johng/comments/commentRss/18.aspx</wfw:commentRss>
            <trackback:ping>http://blogs.sftsrc.com/johng/services/trackbacks/18.aspx</trackback:ping>
        </item>
    </channel>
</rss>