Jump to content
  • Advertisement
Sign in to follow this  

Now this is weird

This topic is 3939 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Below are two snippets of code. The first works, but the second is claiming that "Object reference not set to an instance of an object." As near as I can tell, they're effectively identical, so why does the second one not work? They're written in Visual Basic 2005, and are part of my final project for Intro to Programming. Sad thing is I showed the teacher and he wasn't sure what I did in the first one!
            Dim picButton As System.Windows.Forms.PictureBox
            Dim lstButton As System.Windows.Forms.ListBox
            Do Until Placement > 26
                If Placement < 9 Then
                    picButton = Me.Controls("picSkill0" & (Placement + 1))
                    lstButton = Me.Controls("lstSkill0" & (Placement + 1))
                    picButton = Me.Controls("picSkill" & (Placement + 1))
                    lstButton = Me.Controls("lstSkill" & (Placement + 1))
                End If
                LoadButtonInfo(0, Placement, picButton, lstButton)
                Placement += 1
        Dim BoxRef As System.Windows.Forms.NumericUpDown
        BoxRef = Me.Controls("numAccuracy")
        AttributeChange(0, BoxRef)
Ideas? I'm at a total loss, and searching for hours on the web has yielded nothing relating to this except mention of using something like "Set Boxref =" etc. Problem is when I try to prefix that line with Set, Visual Basic discards it again.

Share this post

Link to post
Share on other sites
Maybe you need to create the BoxRef?

BoxRef = New NumericUpDown()

At least that is how it worked in MSDN sample :

Share this post

Link to post
Share on other sites
Debug your program. There's nothing about debugging that requires any ounce of creativity or intuition, it's merely a process of backtracking through your code until you see the source of all symptoms.

In your case, the symptom is that a given variable is used when it's null. Is the variable expected to be null at that point? If it is, then why are you using it? If it isn't, then this is a symptom that the code which provides you with the variable doesn't work. I'll assume this is the second case here.

So, the new symptom is that Me.Controls("numAccuracy") returns a null when it shouldn't. Under which circumstances does this happen? This is where you read the documentation for that function and find out in what situations it returns null. If you expect to be in this situation, then the code is badly designed. If you don't expect this situation, then find out why it happened by reading the documentation and the previous uses of the object.

Go on like this until you encounter an obvious cause, which you then correct.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!