Ah, the Joys of Coding!

Some time ago, you may recall that I began learning Visual Basic at the request of my employer.  It has not been an easy journey, but it most certainly has been a fun journey.

Take the reason for this post.  I wanted my program to display a form and load certain data from the database into said form.  I wrote the code that should have produced those results, and yet, the program generated an error with a “Null Reference Exception” every time I tried to load the form.

I moved the code that pulled the data from the database to a different place in the code, and when I ran the program in Debug mode, it opened a blank form!

In case you were wondering, this is not what was supposed to happen at all!  I poked around on the problem for a little while, until at last it frustrated me to the point that I put it out of my mind and resolved to take the issue to a higher authority.

In this case, the higher authority was my guide in the coding process: Leith, and I regret to say that I successfully stumped him.  His suggestion, which seemed entirely appropriate to me, was to delete the form and recreate it.  I did just that…and the problem persisted.

Not a happy Geek!

At this point in my frustration, I really favored the idea of printing the code…just so I could take it out onto my back deck and burn it.  In no way would it have solved the problem, but I would’ve taken some measure of satisfaction in the destruction of my frustration.

Me being who I am, though…I vastly prefer a solved problem over a burned effigy.  So I turned to the next higher authority: Stack Overflow.

I posted my problem there, and a user by the name of Hans Passant commented “it is always a coding bug” among several other statements.  I don’t know why, but this jogged my memory of a incident in which Visual Studio suggested an edit to the form in question.

I went to the Code View of the form, found the suggested code that I had allowed Visual Studio to add, and deleted it.  I saved the code, tested it, and…


The form loaded!  I clicked the “Load Series” button (which I had created when I thought it was a problem with pulling the data at load-time), and I was greeted with the proper data from the database!  I closed the Debug session and modified the code to pull the data as the form loaded, saved it, and tested it.  It still worked!

I love solving problems…especially when the problems I solve are my own.  😛

What follows here is a more technical description of the problem’s cause.  It is in no way necessary for the narrative, but any coders who read this post may find this information enjoyable.

Here’s a screen-capture of the EditSeries.vb with the offending code still included:

Here’s a screen-capture without the offending code:

I am not yet familiar enough with Visual Basic to explain why

Public Sub New(seriesID As Integer)
    Me.SeriesID = seriesID
End Sub

broke my form.  Hopefully, I will reach a level of understanding Visual Basic one day that I do.

Stay In The Know!

* indicates required
Email Format

The last comment needs to be approved.