Microsoft Expression Interactive Designer

Ran through a simple Tutorial today using the Beta of Expression Interactive Designer. It’s quite an odd experience, sort of like a cross between a image tool and a traditional Windows form designer, at least as far as the UI is concerned. However, the tutorial wasn’t without its problems.
 
Problem 1, "Namespace is incorrect, please change root namespace element in the project". When I ran the tutorial I got a very strange error. This shows one of the major drawbacks of this tool. Essentially what I guess had happened is that at some point I’d been forced to "Save As" and used a different name, "Fabrikum Tutorial2". Unbeknown to me this create a rootNamespace element, in the actual project file, called "Fabrikum Tutorial2". So after fishing around with the C# code produced (via notepad) it dawned on me that it was using "Fabrikum_Tutorial2", i.e. no spaces. So I manually changed the project by inserting the underscore and hurray it compiled. Now I’m not suggesting that I’m some kind of developer super hero but this tool is aimed at UI designers who shouldn’t have to care about c#, that’s really the point of it. So why show bizzare errors that mean nothing and can’t be fixed without getting low down and dirty with the code. Oh well I guess that’s Beta software.
 
Project 2. Data binding. The first example gets you to set up a number of data bound controls. However, it didn’t work. The automatic synchronising between master and detail panes simply didn’t happen. Opening the finished sample of the code I tried to compare the XAML produced. Now I could see differences but I had no idea how to get these changes via the designer. That’s how I left it, tutorial 1 complete, but with it not working. Score another one for the Beta product, but you’d think at this late stage a simple tutorial should work.

Talking about Visual Studio tips and tricks

This helps with one of my greatest peeves, that of writing too much code on one line. In the age of huge monitors and people that use freakishly small fonts the line length of code can quickly become unreadable for many users.

 

Quote

Visual Studio tips and tricks

Column Guides in Visual Studio

A lot of coding guidelines specify the maximum length for a line of code. For instance in the CLR, Microsoft like to keep lines of code under 110 characters long. Visual Studio has a feature which lets you display a vertical line at the column of your choosing to help visually see when a line is getting too long. This does involve mucking in the registry so the usual disclaimers apply.

To enable this feature, set:

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Text Editor]

"Guides"="RGB(192,192,192) 110"

The values passed to the RGB function let you specify the color of the line, and the number following tells Visual Studio at what column to display it. The

Snippets and auto-stubs

A few more tips for getting the most out of Visual Studio.
 
  • Snippets from Intellisense. When you start to type in the editor you’ll get the trusty intellisense drop down. If there is a snippet available then it also be shown, for example as you start to type t..r..y you’ll see the "try" snippet, but how do you invoke it. After much trial and error yuo need to double tab, i.e. with the try snippet highlighted press tab twice in quick succession
  • Auto-stubs. When you’re inside a function and you realise you have to going to have write another function and call it, then write the the call to the yet-to-exist function an you’ll see a little block appear under the new function name. Selecting that will automatically create the skeleton code for your new function using the arguments (and datatypes).
  • Auto-add "Using". If you add a call to a component you have referenced but don’t specific the full namespace and haven’t yet added it to the "using" statments then a little block will appear under the component. Selecting that will auto-create the correct "using" statement

Navigation shortcuts

Quick tips for navigating around code in Visual Studio 2005.
 
When you select "Goto Definition" you can navigate back to the line in the calling function using one of the following…
1. CTRL-   … move to my last position
2. CTRL * … move to the last calling function
 
The difference between the two is that (1) will move back through every step, so if you page down twice it will page up twice for you. Whereas (2) will simply take you straight back to the previous function.

Converting VBScript to .net

I’ve recently been faced with the prospect of supporting a number of VBScripts in a product written almost exclusively in C#. So rather than continue supporting VBScript I wondered how difficult it would be to convert the VBScript to .NET?
 
So how to convert the code? The obvious answer is to either write a parser or use a commercial converter or parser language. Well I couldn’t find anything (at least not cheaply) that would automatically convert the code. I also rejected the idea of writing a parser since I know from experience that the parser is easy, it’s implementing all the language rules that are tricky. Now that sounds like a good reason but in reality I knew that the VBScripts I’d be supporting are all roughly the same and would only represent a small subset of the available VBScript lexicon so I didn’t really want to spend the time implementing a fully blown solutions, what I needed was a fairly quick and simple answer. I decided that it was about time I learnt regular expressions and it seemed to me that this would provide me with a conversion mechanism.
 
The next problem was which .net language to choose. I spend most my day using C# but business developers don’t tend to like that – again another excuse. The real reason for choosing VB.NET is that it is *very* forgiving and shares a number of functions and keywords with VBScript so should make the conversion easier. So the converter was going to go from VBScript to VB.Net and use RegEx’s to do the donkey work.
 
So using the Regex component of .net I set about producing a converter.
Tasks, including the pattern used;
NB. As you’ll see I’m a RegEx newbie so the patterns used tended to change as I found new ways of doing things, but hey they work.
  1. Ensure Option Explicit is removed – I don’t need it so I’m dropping it from the VBScript – (?i)\s*Option Explicit
  2. VBScript functions and Subs – Pesky devils, the problem here is that function need a "As object" value and all routines really should (in my case) have their arguments prefixed with ByRef to be compatible with the VBScript.
    Find those routines – (?i)(Function|Sub)\\s*[a-z_][a-z_0-9]*\\s*[(](([\\w\\d]*)|(\\s*,\\s*[\\w\\d]*))*[)]
    Remember the name of the routine – (?i)(?<=((Function|Sub)\s*))\w*
    Get the arguments – (\((([\w\d]*)|(,\s*[\w\d]*))*)|(,\s*(([\w\d]*)|(,\s*[\w\d]*))*)
  3. So we’ve converted the routine declaration, but VBScript doesn’t (typically) use brackets when calling a routine and VB.NET requires them, so "lucky" we remembered the names of the routines in step 2.
    Find any caller to a function that isn’t already using brackets and isn’t simply the assignment of the function result – string.Format(@"(?i)(?<!(Function|Sub)\s*){0}(?!(\s*=)|(\s*\())", routineName)
  4. Adding Namespaces – this one caught me out at first, it was fairly obvious that I needed to import "system" but it took a couple of scratched heads to include "Microsoft.VisualBasic", seems obvious now!
  5. The next problem was general differences in keywords and types, etc. The most common one was replacing "now()" with "DateTime.Now". This proved an interesting problem since a number of scripts contained code such as "now()-1", so converting that to "DateTime.Now-1" didn’t cut it since .net can’t correctly cast the integer. So (for some reason) I chose to replace those with DateSerial(0,0,x) – (?i)(?<=DateTime\.Now\s*)(-|+)\d"
    The other common problem was VBScript variables called "Return", so they needed replacing, again nothing fancy just guessed at a unique name, NB return isn’t a valid exit in VBScript –
    replace…(?i)\bReturn\b", "ReturnVarX "
  6. "Set" and "Let" – so Microsoft has finally killed these off, who knew? 😉 – (?i)(?<=\s)set\s*
  7. All done!

So there you go, as long as you’re not guaranteeing 100% VBScript conversion and, like me, have a finite (if large) number of scripts to convert, you can probably convert them all with the minimum of fuss and a few regular expression.

Anti Virus and Visual Studio

The projects I work on are typically big. The frustrating thing about this is that when I "build" the project my Anti-virus tool (McAfee) constantly checks everything. It accounts for up to a 1/3 of the build time! So not only do you suffer from getting a virus, you suffer for trying to avoid them. My advice is to turn off "On-Access scan" whilst building. Far from ideal but what choice is there?

Visual Studio 2005 and Remote Desktop

For some strange reason Visual Studio runs really poorly in a Remote Desktop session. I guess it’s something to do with not being the main interactive desktop? Anyway one way around this problem is to use the lesser known /Console flag when starting up the Remote Desktop client…mstsc.exe /console
 
This enables you to access the interactive console and VS2005 works again. Of course its also useful for grabbing the current users console but not great if you’re trying to share the machine. Still you’re unlikely to be wanting to share VS2005 between many users, it’s not exactly shy when it comes to resources.