Replacing simple factories with Func<TResult> delegate

I’ve recently noticed the emergence of a recurring pattern in my code. Each project has the same class in it, and this duplication has really been bothering me. The solution to this repetition just hit me this morning while I was reading Jon Skeet’s “C# In Depth.”

First, let me illustrate the pattern I was using and why it’s a problem.

I’ve been refactoring 1-tiered legacy code into something testable. This has involved creating a data layer class, typically called DataProvider which implements an IDataProvider interface so that I can easily mock out the data access.  Now, because any kind of data access is extremely likely to have unmanaged resources, IDataProvider extends IDisposable.

Read the rest of this entry »

, , , , , , ,

Leave a comment

Comments on Doc Comments

I was reviewing some VBA code over at Code Review Stack Exchange the other day and it got me to thinking about comments. The code wasn’t too bad, but there were so many comments in the code that, well…

I just read over this again and I think the fact that I mention the comments so often really highlights the issue. I barely even looked at the code because I was too distracted by all the comments.

Read the rest of this entry »

, , , , , ,

Leave a comment

That’s not real experience

I recently had a pretty big change in my life. My company went through an internal reorganization. I was left with a choice of moving my family a few hundred miles or finding new work. Since the prior wasn’t really an option for us, I took the opportunity to make a career move. 

Now was as good a time as any. Luckily, I didn’t have too much trouble finding a replacement job, but finding it was quite an experience. It turns out that nobody is interested in hiring a VB6 developer these days, and if they are, they want to make your job title “Excel Analyst” and severely underpay you. Seriously people, a good VBA dev is worth their weight in gold compared to all the people writing spaghetti with the macro recorder. Find a real programmer and pay them what they’re worth. You may spend more now, but it will save you tremendously in maintenance costs. But I digress…

VB6 was replaced by .Net twelve years ago, so I was looking to move on from VBA development and (professionally) into .Net development anyway. Getting my foot in the door without any professional .Net experience turned out to be quite a task though. I can’t tell you how many times I heard a recruiter or HR screener say, “But where is your .Net experience. All I see is this open source project. Don’t you have any real experience?” Even now, months later, that statement makes my blood boil. Let me tell you folks, experience writing open source software is real experience. The last time I checked, Rubberduck was at over 35,000 lines of code excluding the ANTLR generated code. It’s as large and complex as any CRUD app I’ve created in 5 years of professional software development, if not more so. Open source development teaches you more than just code though. It teaches you a number of other things as well. 
Read the rest of this entry »


VBA and Git the Sequel: This Time it’s Integrated

I’ve talked before about using Git with VBA and also about the importance of using source control and other tools for our work. Truthfully though, using source control with VBA is still hard. This is mostly because getting the code modules into and out of the VB Project is hard, and harder to do right. Well, you may have heard that there’s a new duck in town. It’s taken me about 6 months of spare time, but Rubberduck v1.4 not only has a source control COM library that you can use right in VBA to work with Git VBA repositories, but you can also now branch, commit, pull, push, and merge right from inside of the editor.

Read the rest of this entry »

, , , , , ,


Mocking the VBA Editor: Moq an IEnumerable that Works with Linq

It’s been a rough morning here. I’ve just spent six hours trying to properly create a mock for the VBProject interface. There’s very little information out there about this, so I thought I’d take a moment to jot this down and save someone else the headache. For all the grief this gave me, the solution is amazing simple.

Read the rest of this entry »

, , , , , , , , , ,


Using Hampers Testing: Enter the Factory

I’ve been writing a lot of C# lately, and paying a lot of attention to my test coverage while I’m at it. Everything was going great until I wanted to use the FolderDialogBrowser to let my users select a directory.

FolderDialogBrowser implements IDisposable, so I naturally reached for a Using block.

using (var folderPicker = new FolderBrowserDialog)
    if (folderPicker.ShowDialog() != DialogResult.OK)


Then I stopped dead. I can’t do that. This will display a GUI and any hope of running automated tests against this method is lost. Read the rest of this entry »

, , , , , , , , , , ,

Leave a comment

What’s Up Duck?

I’ve been promising you an update on my pet project, Rubberduck, for quite some time now. I apologize for taking so long to get around to it. Both the project and this blog tend to come last in the grand scheme of my life, so it sometimes takes me some time to get around to things. I’m afraid that may be more or less the theme of this post.

Read the rest of this entry »

, , , , ,

Leave a comment

Iterate over a date range in VBA

After years of VBA development, I’m still learning about the language every day. I was absolutely surprised when I tried this today. You can iterate over a date range just like you can iterate over a range of integers.

Public Sub LoopOverDateRange()
    Const startDate As Date = #5/13/2015#
    Const endDate As Date = #5/20/2015#
    Dim d As Date
    Dim i As Integer
    i = 1
    For d = startDate To endDate
        Debug.Print "Iteration " & i & ":" & vbTab & d
        i = i + 1
End Sub

This code will result in the following output.

Iteration 1:    5/13/2015
Iteration 2:    5/14/2015
Iteration 3:    5/15/2015
Iteration 4:    5/16/2015
Iteration 5:    5/17/2015
Iteration 6:    5/18/2015
Iteration 7:    5/19/2015
Iteration 8:    5/20/2015


, ,


Capturing A Stored Procedure’s Return Value in VBA

Christopher J. McClellan:

Nice little primer on accessing stored procedure return values through ADODB in VBA.

Originally posted on Ramblings:

Those of you who have ever done any serious programming with SQL Server stored procedures will know that they return an integer value to their caller on completion. The default value is ‘0’, which indicates success, and any other value indicates a failure at some stage in its processing. VBA has the power to capture these return values through the ADODB.Command object but, in order to do so, there are a few points you should consider.

1. Invoke Parameters.Refresh before Execute.
2. Specify adCmdStoredProc as the CommandType.
3. Specify an OLE DB provider but don't use MSDASQL.
4. If the Stored Procedure consists of more than one statement (most do) make sure it starts with SET NOCOUNT ON.
5. Poke/prod any returned, open recordset before examining the Return Value.
6. Use a TRY..CATCH block in your Stored Procedure to handle exceptions.
7. Use additional error handling in your VBA code.

View original 1,012 more words

Leave a comment

What is SQL, PL/SQL, T-SQL and difference between them

Christopher J. McClellan:

A brief history of SQL.

Originally posted on SQL with Manoj:

Today I got an email from a student who is pursuing his Bachelors degree in Computer Application (BCA). He visited my blog and sent me an email regarding his confusion with terms like SQL, T-SQL, PL/SQL, and asked me what is differences between them and how are they related? I had a chat with him and told the basic differences, but he further asked me how they are related to Microsoft SQL Server, Oracle, MySQL, etc? As he is studying SQL only based upon Oracle in his course curriculum, these all terms were not clear to him, so I cleared all his doubts while chatting with him.

After a while I had a same reminiscence that when I was a student I also had these doubts and confusions, and there was nobody to guide me, but I gradually came to know about this and it took some…

View original 728 more words

Leave a comment


Get every new post delivered to your Inbox.

Join 329 other followers