How to get one class accessing another class' properties?
Hi,
I must be overlooking something really simple.
SITUATION
A form Application, but this is about the two added Class Modules: Class1.vb and Person.vb
Person.vb
--------------
VB Code:
Public Class Person
Public Name As String
Public Age As Integer
End Class
Class1.vb
-------------
VB Code:
Public Class Class1
Dim person As New Person
person.Name = "Bob" <---- Name doesn't show up in Intelisense and this gives a "Declaration expected" error.
End Class
PS
* They are in the same (root) namespace.
* I know the above Class design is *crappo*. It's just put together as a simple illustration of my headache, I mean problem. (#_#)
Re: How to get one class accessing another class' properties?
I have declared Public variabes in classes before and didn't need to reference the class that it belongs to, to use it. Just try using:
VB Code:
Public Class Class1
Dim person As New Person
Name = "Bob" <---- Name doesn't show up in Intelisense and this gives a "Declaration expected" error.
End Class
Hope that works! ;)
Re: How to get one class accessing another class' properties?
You cannot assign to property of a member variable outside a method.
Re: How to get one class accessing another class' properties?
Add a constructor to the class pewrson that takes a name and use that e.g.
VB Code:
Public Class Person
Public Name As String
Public Age As Integer
Public Sub New(byval NameIn as String)
Name = NameIn
End Sub
End Class
Public Class Class1
Dim person As New Person("Bob")
End Class