|
-
May 11th, 2006, 06:53 AM
#1
Thread Starter
Addicted Member
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. (#_#)
-
May 11th, 2006, 06:56 AM
#2
Fanatic Member
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!
-
May 11th, 2006, 07:14 AM
#3
Re: How to get one class accessing another class' properties?
You cannot assign to property of a member variable outside a method.
-
May 11th, 2006, 07:51 AM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|