0

here is the entire fiddle. https://dotnetfiddle.net/f7VkDe

I have a nested class. however whenever I try to set the inner class it keeps reporting that the inner class is nothing.

Imports System

Public Module Module1
    Public Sub Main()
        Dim result As New WAWFExport()
        result.StartLine = New WAWFStartLine()
        result.StartLine.NbrTx = 1
        Console.WriteLine(result.StartLine.NbrTx)
    End Sub

     Public Class WAWFExport
        Public Property StartLine() As WAWFStartLine
        Get
            Return m_StartLine
        End Get
        Set(value As WAWFStartLine)
            m_StartLine = m_StartLine
        End Set
    End Property
    Private m_StartLine As WAWFStartLine
    end class

    Public Class WAWFStartLine
    Implements IWAWFFormatter

    Public Property NbrTx() As Integer
        Get
            Return m_NbrTx
        End Get
        Set(value As Integer)
            m_NbrTx = value
        End Set
    End Property
    Private m_NbrTx As Integer
    Private sl As WAWFStartLine



    Public Function format() As String Implements IWAWFFormatter.format
        Return String.Format("START*{0}^", m_NbrTx.ToString)
    End Function




End Class

    Friend Interface IWAWFFormatter
        Function format() As String
    End Interface


End Module

Run-time exception (line -1): Object reference not set to an instance of an object.

Stack Trace:

[System.NullReferenceException: Object reference not set to an instance of an object.]

Bryan Dellinger
  • 4,724
  • 7
  • 33
  • 79
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – VDWWD Sep 08 '17 at 13:09

1 Answers1

1

The problem is with the setter of StartLine property. value keyword is reserved for the setter input.

This should be the correct fix m_StartLine = value

Public Class WAWFExport
    Public Property StartLine() As WAWFStartLine
    Get
        Return m_StartLine
    End Get
    Set(value As WAWFStartLine)
        m_StartLine = m_StartLine // Should be, m_StartLine = value
    End Set
End Property
Private m_StartLine As WAWFStartLine
end class
Orel Eraki
  • 11,940
  • 3
  • 28
  • 36