Class Properties
-
I have a class, class A. Within that class are defined multiple properties. (Gets and Sets). In the same project, I have a second class file, Class B. Class A's properties are public, but I am unable to access them from Class B, and when I try to pass Class A into Class B, it doesnt allow it, saying "Class A is a type and cannot be used as an expression". Not sure what I need to do to make Class A Accessible within Class B. Can anyone point me to where I need to go? Thanks
-
I have a class, class A. Within that class are defined multiple properties. (Gets and Sets). In the same project, I have a second class file, Class B. Class A's properties are public, but I am unable to access them from Class B, and when I try to pass Class A into Class B, it doesnt allow it, saying "Class A is a type and cannot be used as an expression". Not sure what I need to do to make Class A Accessible within Class B. Can anyone point me to where I need to go? Thanks
What you need to do is post code. Best guess - you are trying to access them as ClassA.SomeProperty when they are not static. YOu need a class instance ( which holds the value for thqat instance only ) or to make them static ( which I think is Shared in VB )
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
What you need to do is post code. Best guess - you are trying to access them as ClassA.SomeProperty when they are not static. YOu need a class instance ( which holds the value for thqat instance only ) or to make them static ( which I think is Shared in VB )
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Here is what I have, in Class A: Public Class ClassA Private Shared propName As String Public Shared Property strPropName() As String Get Return propName End Get Set(ByVal value As String) propName = value End Set End Property End Class That will allow me to access it as a property directly within another class. (Thanks) However, these properties are set from a VB6 application, which then calls different methods within Class B. I can access the properties in Class B now, but they are not visible in the VB6 app anymore. I have the project setup for Com Interop, and can see everything else, just not the properties I set this way. Am I stuck with one or the other? Or is there a way to get both? I found that if I change the Public Shared Property to just Public Property, I can see it in the vb6 app, but not in the other classes within the project.
-
Here is what I have, in Class A: Public Class ClassA Private Shared propName As String Public Shared Property strPropName() As String Get Return propName End Get Set(ByVal value As String) propName = value End Set End Property End Class That will allow me to access it as a property directly within another class. (Thanks) However, these properties are set from a VB6 application, which then calls different methods within Class B. I can access the properties in Class B now, but they are not visible in the VB6 app anymore. I have the project setup for Com Interop, and can see everything else, just not the properties I set this way. Am I stuck with one or the other? Or is there a way to get both? I found that if I change the Public Shared Property to just Public Property, I can see it in the vb6 app, but not in the other classes within the project.
rahvyn6 wrote:
Or is there a way to get both? I found that if I change the Public Shared Property to just Public Property, I can see it in the vb6 app, but not in the other classes within the project.
Sounds like you can have one or the other. There's no way to do it without having something shared at some point. One possible hack is to have a non shared property which, when called, sets or gets the shared one. So, you have a non shared property, which turns out to really be shared.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
rahvyn6 wrote:
Or is there a way to get both? I found that if I change the Public Shared Property to just Public Property, I can see it in the vb6 app, but not in the other classes within the project.
Sounds like you can have one or the other. There's no way to do it without having something shared at some point. One possible hack is to have a non shared property which, when called, sets or gets the shared one. So, you have a non shared property, which turns out to really be shared.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Sure - I'm afraid I have no other suggestions.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-