December 2007 - Posts
I have been busy installing a new laptop during these last few week. Got a nice an sweet fast machine with a 7200 RPM disk and 4Gb of memory. Now normally any of my machines are slowly but certainly wrecked by a combination of both writing new software myself and installing all sorts of software from others. Not that my software causes much problems (yea right) but all the other, including beta, software tends to wreak havoc on a machine over time.
But no more
With a large fast disk, plenty of memory and a 64 bits version of Vista VMware rocks. I am basically settings up a separate VM for every project I am working on. And I am really happy with the result as I can really configure the VM as it needs to be for that project. No longer any problem when the requirements for one project conflict with another project. Need to work in multiple domains? Something that used to be a problem but no longer And when a project is done I just archive the whole VM as is for when they come back for more.
Exception handling can be quite a tricky subject. How many and which exceptions do you handle and where? But whatever your exception handling strategy is you first need to know exactly what kind of exceptions can to be thrown in the first place.
In Java there is a rule that every function must either catch or declare every possible exception. The result is that a function declaration actually shows the possible exceptions. If that is a good or bad thing is open for discussion, personally I think it just creates a lot of extra work, but it does give some useful insight when deciding which exceptions to catch.
In the .NET world there is no such requirement and the result is that it is a lot harder to see what kind of exceptions might be thrown. And this is especially true when it comes down to the .NET framework code we cannot see (yet).
RedGate saw this as a problem and created a nice utility for tracking down the possible unhandled exceptions in your application. Basically the tool just opens your code, checks all the code that could possibly be executed and reports on any thrown exception that isn't caught. Of course this doesn't solve the complete exception management problem but does offer a good starting point in knowing exactly what exceptions could be thrown. See http://www.red-gate.com/products/Exception_Hunter/index.htm for more details.
Setting Option Strict Off can be a very useful thing in Visual Basic but having project template depend on it being this way certainly isn't a good thing
Unfortunately this is the case with the WPF project template for VB and the result could be a compile error in a new project depending on your default setting of Option Strict. Not a big deal as the error is easy to correct but still a bit of a nuisance. Fortunately the error isn't hard to correct and requires only a single code change. Find the line of code with the error, this should be:
And add a type cast to is like this:
Return CType(Global.System.Windows.Application.Current, Application)
And you should be ready to go. The best place to make this change is in the project template so you only have to do this once. The steps required, and more information, can be found here http://support.microsoft.com/kb/945756
Using COM to automate Word from your Visual Basic application isn't very hard. Just did a sample for a friend and decided to share it. Not that the sample is very complicated or anything, quite the opposite in fact. But it does show how easy it is to get started
The sample code below shows how to construct a minimal document, insert a bookmark and, at a later moment, replace the empty bookmark with some text.
Dim word As
word.Visible = True
Dim doc As Document = word.Documents.Add()
Dim range As Range = doc.Range
' Insert some text
range.InsertAfter("Range1" + vbCrLf)
' Insert a bookmark, make sure the range is 0 characters long so we can insert text
' Add some more text
range.InsertAfter("Range2" + vbCrLf)
' Get a reference to the bookmark
Dim bookmark As Bookmark = doc.Bookmarks(1)
range = bookmark.Range
' Insert the text
range.Text = "Bookmark" + vbCrLf
' Change the font for the bookmark
range.Font.Color = WdColor.wdColorRed
range.Font.Italic = 1
One thing to keep in mind when automating Word is that, in general, it is better to use Range objects instead of the Selection. One reason is that there is only one selection while you can have multiple ranges but there is also a performance penalty to using the selection. And don't forget to install the Office PIA's when using Office through COM from .NET.
Another useful thing is the Word Macro Recorder. It is still there in Word 2007 but hidden away in the Developer Ribbon bar. Kind of strange as the macro recorder was always the simplest way of automating Word for the average user and they typically don't have the developer ribbon visible.
Dennis just posed a session report, with some pictures, about the WF HOL we did last week in the Microsoft Innovation Center in Barneveld. As I reported earlier I think the session went well and think the concept of a regular presentation combined with a hand on lab two weeks later is very interesting and something to be repeated. I certainly enjoyed it
You can find his report here (in Dutch).
In case you were wondering about the competition it is still open. I did receive a few answers but the right one isn't amongst them so you still have a change of winning a copy of "Windows Workflow Foundation, Step by Step" by Kenn Scribner. More details and the downloads here
The hands on labs I did yesterday where very successful and all of us can look back at an evening well spend Thanks to the DotNed user group and Christiaan in particular for organizing this. Now if we only could get rid of the traffic jams, getting there from home took me three hours , a drive that normally would take just one hour. But I guess that is something we will have to learn and live with.
Below are the links to the two samples I created for the HOL session. The first is the console application, the second is the same workflow but now hosted in ASP.NET and activated via a web service. Keep in mind that there is an intentional mistake in the code as a challenge to the attendees. Remember the first to find the mistake wins the book And the mistake is in the way of working with the WF parts so don't bother coming back with database concurrency errors in the UI part!
I will be posting some hints as long as I haven't received the correct answer so stay tuned for more info. And unfortunately the contest is only open for people attending the HOL yesterday.
The console sample
The web service sample
Don’t forget, tomorrow is the HOL that we promised as a follow up from my workflow foundation session two weeks ago for the DotNed user group. There are just a few places left so I you want to come you need to hurry and register here: http://www.dotned.nl/events/default.aspx
See you there