Mathias Brandewinder on .NET, F#, VSTO and Excel development, and quantitative analysis / machine learning.
by Mathias 25. November 2008 22:10
I have been postponing this for a while, but finally did it: I upgraded from BlogEngine 1.3 to 1.4.5. The process was almost perfectly smooth, and whatever the bumps were entirely my own fault: I modified a file as required, but somehow forgot to upload it after that. It's all sorted out and working now, and I couldn't spot any obvious formatting issue so far, so... w00t!
by Mathias 17. November 2008 10:34

During my VSTO add-in session last week-end, the following question came up: what performance difference should I expect if I run code in VSTO instead of VBA? This is particularly important for Excel power users, who leverage VBA to automate their workbooks and run computation intensive procedures. One audience member had a good example: he used VBA to run Monte-Carlo simulations on budget forecasts stored in Excel.

My answer was that I expected VSTO to outperform VBA in the area of pure computation, but that VBA might do better for direct interaction with the application (reading data for instance), because of overhead. However, I had no hard evidence for that, and the question got me wondering, so I decided to run comparisons. My first test confirmed my intuition: on a calculation-heavy procedure, the VSTO code ran about 3 times faster than the equivalent VBA code (30 seconds vs. 1 minute and a half, on the same machine).

More...

by Mathias 16. November 2008 12:26

Someone commented to my post on add-in menus asking if it was possible to add sub-menus to menus - the answer is yes. The code is essentially the same, with one small difference. When you add a menu item to a menu, you will add a CommandBarControl (the menu item) to the controls of a CommandBarPopup, the menu container. If you want to add a "nested" menu to the menu, instead of adding a CommandBarControl, you will add a CommandBarPopup, which can then receive menu items (or more nested menus!).

In code, it would look something like this:

// Add the sub-menu to parentMenu, which is a CommandBarPopup

CommandBarPopup parentCommandBarControl = (CommandBarPopup)parentMenu.Controls.Add(
MsoControlType.msoControlPopup, Type.Missing,
Type.Missing, Type.Missing, true);

parentCommandBarControl.Caption = "Sub-Menu";
parentCommandBarControl.Visible = true;

// Add the menu item to the sub-menu

CommandBarControl commandBarControl = parentCommandBarControl.Controls.Add(
MsoControlType.msoControlButton, Type.Missing,
Type.Missing, Type.Missing, true);

commandBarControl.Caption = menuItemCaption;
commandBarControl.Visible = true;

by Mathias 13. November 2008 18:29

Thanks to you guys who attended my session on VSTO at Silicon Valley Code Camp 2008! This was the first time I gave a talk on VSTO, and I really enjoyed the discussion and questions.

I have put the code I presented up for download here; it includes the TicTacToe "engine", the add-in itself, the installer, and the Excel workbook. As a result, the download is somewhat big - sorry! The purpose of the code was to keep things simple and understandable, and it could definitely be tightened up. Specifically, it is very optimistic in the way it is accessing the data in the workbook: adding some checks for whether a workbook/worksheet are open would be highly recommended... Let me know if you have questions or comments!

by Mathias 11. November 2008 12:21

Thank you to all of you who attended my session on test-driven development for C# developers at Silicon Valley Code Camp 2008!

Here are my slides and, more importantly, the code I presented during the session. In order to get it to work, you will need to install NUnit on your machine first. Besides the unit tests for City, there are 3 files in the folder "Tests". RowTestIllustration is an example of how to use RowTest to pass different set of values to the same test; note the using statement "using NUnit.Framework.Extensions". SetupIllustration shows how the method marked "SetUp" runs before each test method is executed. Finally, "MockIllustration" shows how you can use mocks to easily create instances that satisfy an interface, and verify that the class you are testing conforms to a specified behavior when interacting with that interface.

That's it! Let me know if you have questions or feedback. 

Comments

Comment RSS