Im getting an error "Object reference not set to an instance of an object" in Visual Studio when I try to start the application. I'm using Visual Basic
This is where the error occurs:
Public Overrides Function ToString() As String
Dim strOut As String = String.Format("{0, -20} {1}", LastName, m_address.ToString())
Return strOut
End Function
m_address.ToString() is: (no error on the code below)
Public Overrides Function ToString() As String
Dim strOut As String = String.Format("{0, -20}{1,-10}{2, -10}{3, -10}",
m_street, m_zipCode, m_city, GetCountryString())
Return strOut
End Function
Does anyone know how to fix the error? Thanks!
UPDATE:
Private m_address As Address
'Creates the m_address object in the constructor
Public Sub New()
m_address = New Address()
End Sub
UPDATE V2:
Public Class Address
Private m_street As String
Private m_zipCode As String
Private m_city As String
Private m_country As Countries
'Defualt constructor
Public Sub New()
Me.New(String.Empty, String.Empty, "Malmö")
End Sub
'Constructors
'Constructors calling another constructor
Public Sub New(ByVal steet As String,
ByVal zip As String,
ByVal city As String,
ByVal country As Countries)
Me.m_street = Street
Me.m_zipCode = zip
Me.m_city = city
Me.m_country = country
End Sub
Public Sub New(ByVal street As String, ByVal zip As String, ByVal city As String)
Me.m_street = street
Me.m_zipCode = zip
Me.m_city = city
End Sub
Public Sub New(ByVal theOther As Address)
Me.m_street = theOther.Street
Me.ZipCode = theOther.ZipCode
Me.m_city = theOther.City
End Sub
'Propoties..
Public Function GetCountryString() As String
Dim strCountry As String = m_country.ToString()
strCountry = strCountry.Replace("_", " ")
Return strCountry
End Function
UPDATE V3
'Here i list all the countries in the world
Public Enum Countries
Country 1
Country 2
Country 3
Country 4
etc..
End Enum