Debugging – part deux

In the not so distant past I was bold enough to call Jan and Patrick whiners. But currently I have to extend an application with some functionality and I’ve been debugging it for a few hours now. Overall it’s not that bad, but the things you can come across really make you wonder.



Dim Active As Integer


 


Active = 10


 


Select Case Active


    Case TriState.UseDefault        ‘ -2


        ‘ Do Something


    Case TriState.True              ‘ -1


        ‘ Do Something else


    Case TriState.False            ‘ 0


        ‘ Do Something else


End Select


As you can see in the code above, someone decided to use Active as a variable to store some number. After passing it through some methods, they match it against this weird enumeration from the Microsoft.VisualBasic namespace. Even though it’s an enumeration, it’s still totally unclear what it stands for.


My problem was, that this little (cut-down) piece of code was in a method that was adding SqlParamaters into an array. But as you can see in my example, when you insert the number 10 into Active, it won’t get processed, and thus the array will have a SqlParameter that’s null. When some more methods later this is added into the Microsoft Data Access Application Block (yes, the old one), it throws some weird error.


Part of the problem was the setup of the solution. I first tried to figure out what was happening with Reflector, but didn’t get it. So I rearranged the solutions (yes, multiple), added the Data Access Block and debugged my way through. Only to find out that in my array, SqlParameter number 7 was empty. So after too much time, I could not resist but make the following comment in the code. Although the original developer probably will never read it, it still feels good to get it out of my system this way! 😉



‘ Comment : Any idea why this doesn’t always work?!


‘           Any idea how long it took me to figure out the fault was in here?


‘           So I added a Case Else here, only hoping the UseDefault really


‘           is some sort of weird default, and that it now always works. >-(

You may also like...

3 Responses

  1. If I’m not mistaken that TriState enumeration is used for tristate checkboxes. You know the ones I mean, they can be not checked, checked, or grey (usually because only some of the underlying children are checked)

  2. Good call, but why is it in Microsoft.VisualBasic namespace?! And why do they use it for something that has nothing to do with a checkbox?

    And main problem was the magical Active, matching that against an enumeration. Why not use an enumeration from that start? Or explain what’s done here?! 🙂

  3. I’ve been doing VB.Net over the last couple of months, and I stopped wondering why things were in the Microsoft.VisualBasic namespace.

    But this is just abuse of an enumeration which was meant for something completely different. I know I whine at times, but this should have been detected before the product was released.

Click on a tab to select how you'd like to leave your comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.