Posting tips: Minimal, Yet Complete
When posting code samples that illustrate a problem, it is always a good idea to follow the principle of "Minimal yet Complete".
Minimal means that the problem has been reduced to the absolute bare amount of code necessary to reproduce the error. There should be NO extra code. Quite often, this excercise will reveal the exact nature of the problem, and even prevent the need to post. This is one of the first tenents of debugging an application.
Complete means that EVERY thing needed to re-product the problem is included. Imagine yourself at a bare machine (with the development tools installed), and downloading (or copy/pasting) the posted information to this machine. Can you run the program and see the same symptom (or get the same compile error). If not, then your posting is not complete.
Both of these items are general good practice. And if you follow the tenets of Test Driven Development, you will have already performed these excercies before integrating the code into more complex scenarios.
The vast majority of posts that follow this form, usually get resolution within the first few replies. Those that don't usually suffer from the "Pulling Teeth" problem, where individual details must be dragged out. This wastes tremendous amounts of time (and many members will not expend the effort, preferring to help those who are showing a sincere effort).
So, welcome to CodeGuru, and may you find the assistance your need (remembering of course, that we do not "do" homework ;) ]