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. 😛