-1

I'm back again, I just cant figure out the solution here. Can someone lend me a hand with this? I'm having a problem about "Setting of Object reference to an instance of an object".

PS: I read some links here that is connected to this problem but still no luck. Here is the link "What is a NullReferenceException, and how do I fix it?"

It said, we must check and fill the variable to anything just make sure the variable has a value. But in my case, my variable has a value, why is it returning "NullReference" error ?

Thanks Guys.

BELOW IS MY CODE. (Not the entire module just only the procedure)

    Private m_imp As Object ' We delegate the details of horz or vert to this class

    Public Sub addWidget1(ByRef widget As Object, ByRef minExtent As Object)

        m_widget1 = widget
        'UPGRADE_WARNING: Couldn't resolve default property of object widget.ZOrder. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        widget.ZOrder()
        'UPGRADE_WARNING: Couldn't resolve default property of object m_imp.minExtent1. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        'UPGRADE_WARNING: Couldn't resolve default property of object minExtent. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        m_imp.minExtent1 = minExtent ' <---- HERE IS THE ERROR
    End Sub

ERROR: System.NullReferenceException occurred

screen shot

PS: CODE CALLING THE FUNCTION'S ERROR.

   Private Sub initGUI(ByRef splitter As clsSplitLayout, ByRef navpane As clsPaneNav, ByRef contentpane As clsPaneContent, ByRef detailpane As clsPaneDetail)

    Dim hsplit As New clsSplitLayout
    With hsplit
        .SplitType = clsSplitLayout.SplitterType.HORIZONTAL_SPLIT
        .createSplitBar("bar1", Me)
        .addWidget1(contentpane, 2000)  '<--- HERE'S HOW I CALL THE FUNCTION THAT HAS ERROR.
        .addWidget2(detailpane, 2000)
    End With
Community
  • 1
  • 1
Mr Yoso
  • 29
  • 1
  • 9
  • 4
    Possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – David Oct 12 '15 at 03:09
  • show code where you assign a value to `m_imp` – Igor Oct 12 '15 at 03:09
  • Where do you assign anything to `m_imp`? That's what `null` (`Nothing` in VB) means, it's a reference type which was never assigned. – David Oct 12 '15 at 03:10
  • 1
    You should enable `Option Strict`; your code doesn't make sense. – SLaks Oct 12 '15 at 03:10
  • There is nothing in your question that let's us pin point the answer. This is therefore a duplicate of http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it. You should delete this question or add the code that let's us see the problem. – Enigmativity Oct 12 '15 at 03:17
  • I know it is duplicate. Did you see my link above? As i said, i dont have a variable nothing as stated in the link you guys have given. There's value "2000" there (see image). – Mr Yoso Oct 12 '15 at 03:22
  • Hi Igor and David, yeah, I never assigned m_imp. it is an object.. The equivalent value here is "nothing". how can i assign it? I just converted my VB6 to VB.NET and this is the result. I'm just debugging it. Please respect, specially the one that said NONSENSE. Thanks Guys :)) – Mr Yoso Oct 12 '15 at 03:26
  • You should turn on Option Strict too and fix the errors the compiler points out. Study the link – Ňɏssa Pøngjǣrdenlarp Oct 12 '15 at 03:29

1 Answers1

0

System.NullReferenceException occurs when you're reading a variable that has n value in it.

In your case, m_imp is defined but it has no value.

Before you access m_imp, m_imp must have a value.

  • Yes, can you give me a sample/generic value? I really don't know, I just migrated my VB6 to VB.NET. :salute: – Mr Yoso Oct 12 '15 at 03:31