William Bartholomew

Musings on software engineering, technology and Aspergers Syndrome.

Quick Excel Macro: Remove All Pictures

leave a comment »

I pasted some content into Excel, and while I did want the formatting, I didn’t want the pictures it included. This meant I couldn’t use Paste Special.

Solution? A quick macro to remove all shapes from the sheet after I pasted:

Public Sub RemoveAllShapes()
    For Each e In Shapes
        e.Delete
    Next
End Sub

Written by wbarthol

July 31, 2009 at 10:32 am

Posted in programming

Snagit Accessory Installer

leave a comment »

I’ve used Snagit from TechSmith for a year or so now and despite not being free it is without a doubt the best screen capture software I’ve used and I recommend it to anyone that asks me about screen capture software.This post actually isn’t about any of it’s screen capture capabilities but part of their installation. Snagit allows you to install what are called “accessories” (aka plugins) to add additional capabilities to the software. In fact, I’m writing this post with their WordPress.com accessory.

Plugins are certainly not a new concept by any stretch of the imagination, but what impressed me about TechSmith’s implementation is the installation process. Plugins aren’t normally a user-friendly concept because they usually involve putting files in special locations or doing special configuration.

TechSmith take away this complexity by registering a file extension (*.snagacc). These files are effectively a Zip file containing the DLLs and any dependencies of the plugin as well as a “manifest” containing information about the plugin. This file extension is registered to Snagit and the result is that simply double-clicking the *.snagacc file does all of the copying and configuration necessary for that plugin.

I’m impressed by the simplicity (for both the user and the plugin author) of this technique. The use of a renamed Zip file is now a common one and is used by Office 2007 for *.docx, *.pptx, *.xlsx, etc. and this is just another example of the usefulness of this technique.

Written by wbarthol

June 20, 2009 at 9:51 am

Posted in programming, utility

VSTO Deployment Error: The required version of the .NET Framework is not installed on this computer

leave a comment »

I’ve been going crazy to try and solve a problem with a VSTO package I was publishing. Users were receiving the error “The required version of the .NET Framework is not installed on this computer” even though they had the correct .NET Framework version. It turns out that there is a file missing from the .NET Framework 3.5 installation in Windows 7 Beta/RC that causes any packages published from a Windows 7 Beta/RC machine to display this error.

For more details and the workaround read:

http://blogs.msdn.com/vsto/archive/2009/05/07/issues-with-installing-vsto-projects-that-were-published-from-visual-studio-2008-on-windows-7-rc-saurabh-bhatia.aspx#comments

Written by wbarthol

June 11, 2009 at 4:03 pm

Posted in dotnet, programming

Arrowhead Anti-Pattern

leave a comment »

It is a common belief that methods should have a single entry and exit point. While this is a noble goal you need to be very aware that you can detract from the readability and comprehensibility of your code simply to uphold that belief. While a single exit point is not an anti-pattern striving to achieve a single exit point can result in deeply nested “arrowhead” code which is an anti-pattern.

My basic advice to you is that you should only strive for a single exit point from your method when it aids in the readability and comprehensibility of that method, if it doesn’t then don’t get caught up in having a single exit point.

http://www.lostechies.com/blogs/chrismissal/archive/2009/05/27/anti-patterns-and-worst-practices-the-arrowhead-anti-pattern.aspx

Written by wbarthol

May 31, 2009 at 7:54 pm

Posted in dotnet, programming

Validating XML files against an XML Schema (XSD)

leave a comment »

UPDATE: You must set the ValidationFlags property to XmlSchemaValidationFlags.ReportValidationWarnings and you must add the event handler before calling Create on XmlReader, otherwise the event won’t be raised.

Validating XML files against an XML Schema (XSD) has changed slightly in .NET Framework 3.5 because the XmlValidatingReader has been obsoleted as have XmlReader’s constructors. The correct way to validate an XML file now is to:

  1. Create an XmlReaderSettings class, set the ValidationType to ValidationType.Schema, set the validation flags to report warnings, and add your schema to the Schemas collection.
  2. Add a handler for the ValidationEventHandler event, unusually this event is raised from the XmlReaderSettings class not the XmlReader class.
  3. Use the Create factory method on XmlReader passing in the path to the XML file and the XmlReaderSettings object you created above.
  4. Iterate through all of the nodes in the XmlReader (validation is done as the reader processes each node).
  5. Close the reader.
  6. Remove the event handler.

Here is an example:

Dim settings As New XmlReaderSettings()
settings.ValidationType = ValidationType.Schema
settings.Schemas.Add("http://tempuri.org/MySchema.xsd", "MySchema.xsd"))
settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings

Try
    AddHandler settings.ValidationEventHandler, AddressOf ValidationEventHandler 

    Using reader As XmlReader = XmlReader.Create("MyInstance.xml", settings)
        While reader.Read()
        End While

        reader.Close()
    End Using
Finally
     RemoveHandler settings.ValidationEventHandler, AddressOf ValidationEventHandler
End Try
...
Private Sub ValidationEventHandler(ByVal sender As Object, ByVal e As ValidationEventArgs)
    ...
End Sub

Written by wbarthol

May 31, 2009 at 6:27 pm

Posted in dotnet, programming

Unity 1.2 Hands-on Labs and Advertising Injectable Dependencies

leave a comment »

Hand-on Labs for Unity 1.2 are now available (via J.D. Meier). Unity is a very simple and lightweight dependency injection container.

One of the features of Unity is the ability to define type aliases that allow you to define the full type name once and then use an alias to refer to it elsewhere in the configuration. For example:

<unity>
    <typeAliases>
        <typeAlias alias="IClipboard"
            type="MyApplication.Services.Clipboard.IClipboard, MyApplication" />
    </typeAliases>
</unity>

While working through the examples in the hands-on labs it occurred to me that this is a good way of advertising the different dependencies that can be injected. By defining a type alias for each of the dependencies that can be injected (both mandatory and optional) then developers wanting to extend your application can easily see the available dependencies.

For example:

<unity>
    <typeAliases>
        <!--Mandatory-->
        <typeAlias alias="IClipboard"
            type="MyApplication.Services.Clipboard.IClipboard, MyApplication" />
        <typeAlias alias="IStore"
            type="MyApplication.Services.Store.IStore, MyApplication" />

        <!--Optional-->
        <typeAlias alias="ILogger"
            type="MyApplication.Services.Logger.ILogger, MyApplication" />
    </typeAliases>
</unity>

Written by wbarthol

April 5, 2009 at 7:49 pm

Posted in dotnet, programming

Web Usability

with 3 comments

I just had a horrible experience with a software vendor’s website (no, I won’t name them, but it’s a big company) that I wanted to share. Partly to get it off my chest, and party so others can learn from their mistake.

What was my goal? Download a trial of their software.

  1. I clicked the Try button to download the trial. So far so good.
  2. I’m asked to login or register. Why? Just let me try the software, if it’s good software I’ll buy it, I don’t need your salesforce hounding me. But I’ll play your game.
  3. I think I already have a login, so I enter my email and guess the password. Nope, wasn’t that. At least it told me my email was correct, it was just the password that’s wrong. I know this isn’t the best security but at least I didn’t try to register again just to be told my email is already registered.
  4. I click the I forgot my password link. It asks me for my email address. Why? I just entered it! It even told me it was correct, why do I need to tell it again?
  5. I enter my password and click Continue. It tells me I don’t have a password hint so I have to proceed to Step 2. I look around the page and find Step 2, it consists of a single button named Send Email which sends me the password. Why did I have to click the button? Why didn’t it do it automatically as soon as it realised I don’t have a password hint?
  6. I get an email with a link in it, which I click.
  7. It then asks me for my email address. Haven’t I entered this before? Oh yeah, twice now. I play their game and enter it along with the new password.
  8. It then takes me back to the login screen. Where I enter my email address (for the fourth time) and my password (for the third time). Why do I need to login? I just proved my identity what security does this login add?
  9. Finally, I’m authenticated. But, instead of taking me to the original screen I asked for I’m taken to my account details and then need to navigate back to the original page I wanted.
  10. As a final insult, their download insists I use their download manager. Why can’t I just click download? If the download fails that’s my problem, not theirs.

Written by wbarthol

April 1, 2009 at 12:38 pm

Posted in Uncategorized

Get a 10% discount and an opportunity for a free retake on a Microsoft Certification Exam

with 2 comments

It’s a New Year and a great opportunity to complete those certification exams you’ve always been meaning to do. Microsoft have just the promotion to give you that push.

Go to www.learnANDcertify.com and key in AU2EAEAB and complete the Request Form. You will receive an Exam Offer Voucher Code valid for a 10% discount on your first Microsoft Certification exam and if you fail on your first try, a free retake of the same exam (both exams must be taken by May 31, 2009)

Terms & Conditions:

  • The Exam Offer Voucher Code are only valid for a Microsoft Certified Technical Specialist (MCTS), Microsoft Certified IT Professional
    (MCITP) or Microsoft Certified Professional Developer (MCPD) exams. Not valid for Academic Exams.
  • The Exam Offer Voucher Code is only valid for exam candidates in the country where the MVP resides.
  • The Exam Offer Voucher Code may only be used at an authorized Prometric Testing Center
  • Exam candidates must request an Exam Offer Voucher Code using the unique MVP Certification Promotion Code by March 31, 2009 via
    www.learnandcertify.com
  • To receive a 10% discount on the cost of an applicable Microsoft Certification exam, exam candidates must use the Exam Offer Voucher Code provided by an MVP when they register for an exam and sit for an exam by May 31, 2009.
  • Limited to one (1) free exam and one (1) free retake (if necessary) per individual.
  • The Exam Offer Voucher Code may only be used by the exam candidate receiving the Voucher Code and may not be transferred to and/or used by any other individual.
  • The Exam Offer Voucher Code may not be combined with other vouchers or discounts and are void if altered or revised in any way.
  • The Exam Offer Voucher Code may not be redeemed for cash, credit, or refund.
  • Microsoft is not responsible for Exam Offer Voucher Code that are lost or stolen.
  • Any resale of an Exam Offer Voucher Code is expressly prohibited.

Written by wbarthol

January 7, 2009 at 1:18 pm

Posted in Uncategorized

Professional Development: Reading

leave a comment »

In an effort to get more value out of the time I spend reading I’ve been working on a new process which I’ll outline here for those that are interested in doing the same.

Problems

Processes are pointless unless you know what you’re trying to achieve and in this case it was to solve the following problems.

Distractibility

One of the best things about the IT industry (and in particular software development) is how quickly new technologies and processes are introduced. The flipside of this is that it is very easy to be distracted and jump from reading material to reading material. Like any context switch this is inefficient, and results in poor comprehension and lots of half read material.

Lack of Application

People typically read fiction for pure enjoyment, and while you may enjoy reading non-fiction (as I do) it is usually done to improve your knowledge and skills. While knowledge and skills will increase to some degree just by reading the material actively keeping the goal in mind will result in an increased ability to apply and take action on the material you’ve read.

Solution

With those problems in mind lets look at the process I’ve put in place to reduce distractibility and improve the application of the material I’m reading.

Reading List

The main purpose of the Reading List is to reduce distractibility. I’ve used the Scrum concept of a backlog to manage the material I’m reading or want to read. The material may be books or could just as easily be web-based articles or even blog posts (although short reading material is usually read on the spot rather than being added to the Reading List).

In OneNote (although you could use anything from Notepad to a database) I have a page called Reading List that is divided into three sections:

  1. Current Sprint
  2. Backlog
  3. Completed

The Current Sprint section contains the list of reading material that I’m actively reading. I aim to only have a single book in the Current Sprint list. The use of the term sprint is a stretch because there is not a defined length of time, the sprint finishes when I finish reading the book. When moved from the Backlog to the Current Sprint the hyperlink is replaced with a link to the OneNote page where I’m taking notes about the reading material (refer to Note Taking below).

The Backlog is the heart of the Reading List and contains the list of reading material I would like to read. Whenever I come across something that I’d be interested in reading I add it to the top of the backlog. The reason I add it to the top is that things at the top of the list are likely to be more relevant to things I’ve been working on recently. The Backlog is a stack ranked and I always read the first item of the list but I do review the rankings periodically and when I’ve finished reading the material in the Current Sprint. Each item in the list is hyperlinked to where it can be obtained from.

The Completed section contains the list of reading material that I’ve finished reading and since the item is moved from the Current Sprint to Completed section the hyperlink will allow me to review the notes I took at anytime in the future.

Note Taking

One of the best ways to increase comprehension is to take notes and paraphrase as you’re reading. To aid this I create a page in OneNote for each piece of reading material and divide the page into a section for each chapter (allowing me to quickly refer back to the original material if I need more detail about a note I took).

Sometimes I may come up with my own ideas while reading something and I include these along with the other notes I’ve taken (but differentiated in someway – I use italics) because it provides context.

Next Actions

The last thing I do after reading something is to read back over my notes and try to identify the next actions I want to take away from what I read. These help me apply what I’ve read to my day to day work. I actually got this idea from J.D. Meier.

Written by wbarthol

January 4, 2009 at 8:28 pm

Posted in Uncategorized

Running Virtual Server 2005 R2 on Windows Home Server

leave a comment »

Windows Home Server is without a doubt one of the most useful additions to a home network. It provides three main features:

  • Backup of client machines
  • Shared storage
  • Remote access to shared storage and client machines

This allows me to do complete backups both my partner’s and my machine as well as share files. As an added bonus it can stream music (and probably videos) to my XBox 360.

Because of the amount of work I do with Visual Studio Team System I thought it would be useful to have a Team Foundation Server at home and although I have spare hardware I didn’t really want to have to set up and maintain another machine (or pay for the electricity it would use!).

The solution was to install Virtual Server 2005 (which is free) on my Windows Home Server machine and then run Team Foundation Server as a virtual machine on the same host. The process to do this was relatively simple:

  1. Download Virtual Server 2005 R2 SP1.
  2. Remote desktop to the Windows Home Server.
  3. Install Virtual Server 2005 SP1.
  4. Using the Windows Home Server Console created a share (called VirtualMachines) and grant my user Full access to the share. Because the Virtual Server Administration Website impersonates the user you connect as you cannot see or create virtual machines on the share unless you have Full access to it.
  5. Open the Virtual Server Administration Website and login to it using the Windows Home Server’s Administrator account (at this point your normal user account doesn’t have the necessary permissions).
  6. In Server Properties | Virtual Server Security add an entry for your user account.
  7. In Server Properties | Virtual Machine Remote Control (VMRC) Server:
    1. Click the Enable checkbox.
    2. Select NTLM from the Authentication dropdown list. If you don’t do this you will get an Authentication Failed error when you try to remotely control the virtual machine.
  8. In Server Properties | Virtual Server Search Paths change the Default Virtual Machine Configuration Folder to the UNC path to the VirtualMachines share you created (for example, \\myhomeserver\VirtualMachines\).
  9. You can now create and run virtual machines on your Windows Home Server.

Written by wbarthol

December 13, 2008 at 10:30 pm