MatP Posted May 11, 2005 Posted May 11, 2005 Ok, I'm not enough familiar with class for doing what I'm looking for. I have two classes, keeping it simple, say Class1 and Class2. Now, Class2 contain a property in it that is class1 (Class2 is not a collection of class1) : Let's keep it simple, here is the Class1 code: Code: Public Class Class1 Private _Prop1 as String Public Property PropClass1() Get Return _Prop1 End Get Set(ByVal Value) _Prop1 = Value End Set End Class Now for the Class2 Code : Code: Public Class Class2 Private _Prop2 as Class1 ******* Public Property PropClass2() Get Return _Prop2 End Get Set(ByVal Value) _Prop2 = Value End Set End Class What do I need to change in class1 or class2 to make the PropClass1 accessible from a Class2 Object ? What I would like is to be able to do: Code: Dim myClass as Class2 Class2.PropClass2.PropClass1 = "I changed the Property of the PropClass1 of the _Prop2 Object in Class 2, Yeah" Actually, with the code above, Class2.PropClass2 is accessible, but not the ".PropClass1" part. What I need to do for now is: Code: Dim myClass1 as Class1 Dim myClass2 as Class2 myClass1.PropClass1 = "blabalblaa" myClass2.PropClass2 = myClass1 That way it works, but I do not want this. In other words, I would like PropClass2 of Class2 to have sub-properties that are the same as the class1 properties, since PropClass2 is a Class1. Hope it was understandable... Quote
Administrators PlausiblyDamp Posted May 11, 2005 Administrators Posted May 11, 2005 I notice you are not creating a valid instance of Class1 within Class2 - try making the following change to your code and see if that fixes the problem Public Class Class2 Private _Prop2 As New Class1 '******* Public Property PropClass2() Get Return _Prop2 End Get Set(ByVal Value) _Prop2 = Value End Set End Property End Class Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
MatP Posted May 11, 2005 Author Posted May 11, 2005 I notice you are not creating a valid instance of Class1 within Class2 - try making the following change to your code and see if that fixes the problem Public Class Class2 Private _Prop2 As New Class1 '******* Public Property PropClass2() Get Return _Prop2 End Get Set(ByVal Value) _Prop2 = Value End Set End Property End Class It doesn't work either. Well, is it that bad if instead of declaring _Prop2 as Private, I declare it as Public and that way I can access its properties, but it won't be anymore a property of Class2, but an object that I can access outside of the class. Quote
Administrators PlausiblyDamp Posted May 11, 2005 Administrators Posted May 11, 2005 Are you wanting to access an instance of class2 or just the class itself? i.e. as it stands Dim aClass As New Class2 aClass.PropClass2.PropClass1 = "I changed the Property of the PropClass1 of the _Prop2 Object in Class 2, Yeah" will work. If you really want to go through the class name then you will need to declare both the property and _Prop 2 as being shared (I doubt that is what you want from you code though). s Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
MatP Posted May 11, 2005 Author Posted May 11, 2005 Are you wanting to access an instance of class2 or just the class itself? i.e. as it stands Dim aClass As New Class2 aClass.PropClass2.PropClass1 = "I changed the Property of the PropClass1 of the _Prop2 Object in Class 2, Yeah" will work. If you really want to go through the class name then you will need to declare both the property and _Prop 2 as being shared (I doubt that is what you want from you code though). s But if I consider the autoComplete options, once I wrote the second dot, the only thing that is accessible after PropClass2, it's GetType. So I guess that maybe I can access the properties of Class1, but it will be in conflict with Option Strict. Quote
Administrators PlausiblyDamp Posted May 11, 2005 Administrators Posted May 11, 2005 Public Class Class2 Private _Prop2 As New Class1 '******* Public Property PropClass2() As Class1 Get Return _Prop2 End Get Set(ByVal Value As Class1) _Prop2 = Value End Set End Property End Class Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
MatP Posted May 11, 2005 Author Posted May 11, 2005 Public Class Class2 Private _Prop2 As New Class1 '******* Public Property PropClass2() As Class1 Get Return _Prop2 End Get Set(ByVal Value As Class1) _Prop2 = Value End Set End Property End Class Oops.. yes I forgot to put the type at the property. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.