|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Public Shared Propertyby external programs. I decided to include 1 Class with 1 property in this project. I placed this code in Class: Public Class COM Private mMyProp As String Public Property MyProp() As String Get Return mMyProp End Get Set(ByVal value As String) mMyProp = value End Set End Property End Class I compiled the project, created another project (Windows Forms) and added this code to it: Private obj As Object Private Sub Command1_Click() Set obj = CreateObject("SharedTestDLL.COM") obj.MyProp = "Test" MsgBox obj.MyProp End Sub Everything is fine so far. But I wouldn't want to create an object, so I added for testing purposes another Property as Public Shared: Public Class COM Private mMyProp As String Private Shared mMyProp2 As String Public Property MyProp() As String Get Return mMyProp End Get Set(ByVal value As String) mMyProp = value End Set End Property Public Shared Property MyProp2() As String Get Return mMyProp2 End Get Set(ByVal value As String) mMyProp2 = value End Set End Property End Class I also added the code to work with the second property in my client: obj.MyProp2 = "Test2" MsgBox obj.MyProp2 I'm getting an error: Object doesn't support this property or method. Obviously I do not understand Shared stuff. What am I doing wrong? I tried the same code with Early Binding and it did not work too. So, how do I create and use properties without creating an object in the client? Thank you Al The problem is you are still accessing the property through the object
reference 'obj', which you presumably never instantiate. You are supposed to access shared member through the class name. Like: COM.MyProp2 Additionally, I am not sure why you are calling CreateObject? This is just a ..NET class. Use a constructor if you want an instance of it. Show quoteHide quote "Al" <a*@newsgroups.com> wrote in message news:et$YGnpqGHA.2232@TK2MSFTNGP04.phx.gbl... > I'd like to create Class Library in VB 2005, which has a property > accessible by external programs. > I decided to include 1 Class with 1 property in this project. > I placed this code in Class: > Public Class COM > > Private mMyProp As String > > Public Property MyProp() As String > > Get > > Return mMyProp > > End Get > > Set(ByVal value As String) > > mMyProp = value > > End Set > > End Property > > End Class > > I compiled the project, created another project (Windows Forms) and added > this code to it: > Private obj As Object > Private Sub Command1_Click() > Set obj = CreateObject("SharedTestDLL.COM") > obj.MyProp = "Test" > MsgBox obj.MyProp > End Sub > Everything is fine so far. > > But I wouldn't want to create an object, so I added for testing purposes > another Property as Public Shared: > > Public Class COM > > Private mMyProp As String > > Private Shared mMyProp2 As String > > Public Property MyProp() As String > > Get > > Return mMyProp > > End Get > > Set(ByVal value As String) > > mMyProp = value > > End Set > > End Property > > Public Shared Property MyProp2() As String > > Get > > Return mMyProp2 > > End Get > > Set(ByVal value As String) > > mMyProp2 = value > > End Set > > End Property > > End Class > > I also added the code to work with the second property in my client: > obj.MyProp2 = "Test2" > MsgBox obj.MyProp2 > I'm getting an error: > Object doesn't support this property or method. > > Obviously I do not understand Shared stuff. What am I doing wrong? > I tried the same code with Early Binding and it did not work too. > > So, how do I create and use properties without creating an object in the > client? > > Thank you > Al > Thank you, Marina.
How do I access shared member from an external program? I wanted to make the property Shared to avoid creating Objects inside of DLL by other Classes and Windows Forms. And inside of DLL this approach works. But I need to access those properties from outside of DLL as well. Al Show quoteHide quote "Marina Levit [MVP]" <someone@nospam.com> wrote in message news:e7VictpqGHA.4408@TK2MSFTNGP04.phx.gbl... > The problem is you are still accessing the property through the object > reference 'obj', which you presumably never instantiate. > > You are supposed to access shared member through the class name. > > Like: COM.MyProp2 > > Additionally, I am not sure why you are calling CreateObject? This is just > a .NET class. Use a constructor if you want an instance of it. > > "Al" <a*@newsgroups.com> wrote in message > news:et$YGnpqGHA.2232@TK2MSFTNGP04.phx.gbl... >> I'd like to create Class Library in VB 2005, which has a property >> accessible by external programs. >> I decided to include 1 Class with 1 property in this project. >> I placed this code in Class: >> Public Class COM >> >> Private mMyProp As String >> >> Public Property MyProp() As String >> >> Get >> >> Return mMyProp >> >> End Get >> >> Set(ByVal value As String) >> >> mMyProp = value >> >> End Set >> >> End Property >> >> End Class >> >> I compiled the project, created another project (Windows Forms) and added >> this code to it: >> Private obj As Object >> Private Sub Command1_Click() >> Set obj = CreateObject("SharedTestDLL.COM") >> obj.MyProp = "Test" >> MsgBox obj.MyProp >> End Sub >> Everything is fine so far. >> >> But I wouldn't want to create an object, so I added for testing purposes >> another Property as Public Shared: >> >> Public Class COM >> >> Private mMyProp As String >> >> Private Shared mMyProp2 As String >> >> Public Property MyProp() As String >> >> Get >> >> Return mMyProp >> >> End Get >> >> Set(ByVal value As String) >> >> mMyProp = value >> >> End Set >> >> End Property >> >> Public Shared Property MyProp2() As String >> >> Get >> >> Return mMyProp2 >> >> End Get >> >> Set(ByVal value As String) >> >> mMyProp2 = value >> >> End Set >> >> End Property >> >> End Class >> >> I also added the code to work with the second property in my client: >> obj.MyProp2 = "Test2" >> MsgBox obj.MyProp2 >> I'm getting an error: >> Object doesn't support this property or method. >> >> Obviously I do not understand Shared stuff. What am I doing wrong? >> I tried the same code with Early Binding and it did not work too. >> >> So, how do I create and use properties without creating an object in the >> client? >> >> Thank you >> Al >> > > It doesn't matter what DLL the class is in. It's exactly the same.
Show quoteHide quote "vul" <a**@optonline.net> wrote in message news:OdbE$ypqGHA.1852@TK2MSFTNGP03.phx.gbl... > Thank you, Marina. > How do I access shared member from an external program? > I wanted to make the property Shared to avoid creating Objects inside of > DLL by other Classes and Windows Forms. And inside of DLL this approach > works. > But I need to access those properties from outside of DLL as well. > > Al > > > "Marina Levit [MVP]" <someone@nospam.com> wrote in message > news:e7VictpqGHA.4408@TK2MSFTNGP04.phx.gbl... >> The problem is you are still accessing the property through the object >> reference 'obj', which you presumably never instantiate. >> >> You are supposed to access shared member through the class name. >> >> Like: COM.MyProp2 >> >> Additionally, I am not sure why you are calling CreateObject? This is >> just a .NET class. Use a constructor if you want an instance of it. >> >> "Al" <a*@newsgroups.com> wrote in message >> news:et$YGnpqGHA.2232@TK2MSFTNGP04.phx.gbl... >>> I'd like to create Class Library in VB 2005, which has a property >>> accessible by external programs. >>> I decided to include 1 Class with 1 property in this project. >>> I placed this code in Class: >>> Public Class COM >>> >>> Private mMyProp As String >>> >>> Public Property MyProp() As String >>> >>> Get >>> >>> Return mMyProp >>> >>> End Get >>> >>> Set(ByVal value As String) >>> >>> mMyProp = value >>> >>> End Set >>> >>> End Property >>> >>> End Class >>> >>> I compiled the project, created another project (Windows Forms) and >>> added this code to it: >>> Private obj As Object >>> Private Sub Command1_Click() >>> Set obj = CreateObject("SharedTestDLL.COM") >>> obj.MyProp = "Test" >>> MsgBox obj.MyProp >>> End Sub >>> Everything is fine so far. >>> >>> But I wouldn't want to create an object, so I added for testing purposes >>> another Property as Public Shared: >>> >>> Public Class COM >>> >>> Private mMyProp As String >>> >>> Private Shared mMyProp2 As String >>> >>> Public Property MyProp() As String >>> >>> Get >>> >>> Return mMyProp >>> >>> End Get >>> >>> Set(ByVal value As String) >>> >>> mMyProp = value >>> >>> End Set >>> >>> End Property >>> >>> Public Shared Property MyProp2() As String >>> >>> Get >>> >>> Return mMyProp2 >>> >>> End Get >>> >>> Set(ByVal value As String) >>> >>> mMyProp2 = value >>> >>> End Set >>> >>> End Property >>> >>> End Class >>> >>> I also added the code to work with the second property in my client: >>> obj.MyProp2 = "Test2" >>> MsgBox obj.MyProp2 >>> I'm getting an error: >>> Object doesn't support this property or method. >>> >>> Obviously I do not understand Shared stuff. What am I doing wrong? >>> I tried the same code with Early Binding and it did not work too. >>> >>> So, how do I create and use properties without creating an object in the >>> client? >>> >>> Thank you >>> Al >>> >> >> > > Could you give me the code for accessing property in DLL from external
program (VB client), please. Because I'm still confused. Thank you Al Show quoteHide quote "Marina Levit [MVP]" <someone@nospam.com> wrote in message news:O%23x$J4pqGHA.3380@TK2MSFTNGP04.phx.gbl... > It doesn't matter what DLL the class is in. It's exactly the same. > > "vul" <a**@optonline.net> wrote in message > news:OdbE$ypqGHA.1852@TK2MSFTNGP03.phx.gbl... >> Thank you, Marina. >> How do I access shared member from an external program? >> I wanted to make the property Shared to avoid creating Objects inside of >> DLL by other Classes and Windows Forms. And inside of DLL this approach >> works. >> But I need to access those properties from outside of DLL as well. >> >> Al >> >> >> "Marina Levit [MVP]" <someone@nospam.com> wrote in message >> news:e7VictpqGHA.4408@TK2MSFTNGP04.phx.gbl... >>> The problem is you are still accessing the property through the object >>> reference 'obj', which you presumably never instantiate. >>> >>> You are supposed to access shared member through the class name. >>> >>> Like: COM.MyProp2 >>> >>> Additionally, I am not sure why you are calling CreateObject? This is >>> just a .NET class. Use a constructor if you want an instance of it. >>> >>> "Al" <a*@newsgroups.com> wrote in message >>> news:et$YGnpqGHA.2232@TK2MSFTNGP04.phx.gbl... >>>> I'd like to create Class Library in VB 2005, which has a property >>>> accessible by external programs. >>>> I decided to include 1 Class with 1 property in this project. >>>> I placed this code in Class: >>>> Public Class COM >>>> >>>> Private mMyProp As String >>>> >>>> Public Property MyProp() As String >>>> >>>> Get >>>> >>>> Return mMyProp >>>> >>>> End Get >>>> >>>> Set(ByVal value As String) >>>> >>>> mMyProp = value >>>> >>>> End Set >>>> >>>> End Property >>>> >>>> End Class >>>> >>>> I compiled the project, created another project (Windows Forms) and >>>> added this code to it: >>>> Private obj As Object >>>> Private Sub Command1_Click() >>>> Set obj = CreateObject("SharedTestDLL.COM") >>>> obj.MyProp = "Test" >>>> MsgBox obj.MyProp >>>> End Sub >>>> Everything is fine so far. >>>> >>>> But I wouldn't want to create an object, so I added for testing >>>> purposes another Property as Public Shared: >>>> >>>> Public Class COM >>>> >>>> Private mMyProp As String >>>> >>>> Private Shared mMyProp2 As String >>>> >>>> Public Property MyProp() As String >>>> >>>> Get >>>> >>>> Return mMyProp >>>> >>>> End Get >>>> >>>> Set(ByVal value As String) >>>> >>>> mMyProp = value >>>> >>>> End Set >>>> >>>> End Property >>>> >>>> Public Shared Property MyProp2() As String >>>> >>>> Get >>>> >>>> Return mMyProp2 >>>> >>>> End Get >>>> >>>> Set(ByVal value As String) >>>> >>>> mMyProp2 = value >>>> >>>> End Set >>>> >>>> End Property >>>> >>>> End Class >>>> >>>> I also added the code to work with the second property in my client: >>>> obj.MyProp2 = "Test2" >>>> MsgBox obj.MyProp2 >>>> I'm getting an error: >>>> Object doesn't support this property or method. >>>> >>>> Obviously I do not understand Shared stuff. What am I doing wrong? >>>> I tried the same code with Early Binding and it did not work too. >>>> >>>> So, how do I create and use properties without creating an object in >>>> the client? >>>> >>>> Thank you >>>> Al >>>> >>> >>> >> >> > > I did give you code. If your class name is COM, and the property is named
MySharedProp2, you would just say "COM.MySharedProp2". That is all there is. If you could create an instance of the class in the other program, then you can certainly access a shared property. It sounds to me like you are missing something else much more basic, although what that is hard to say with the information you provided. Show quoteHide quote "Al" <a*@newsgroups.com> wrote in message news:uUOrPRqqGHA.3484@TK2MSFTNGP04.phx.gbl... > Could you give me the code for accessing property in DLL from external > program (VB client), please. Because I'm still confused. > Thank you > Al > > "Marina Levit [MVP]" <someone@nospam.com> wrote in message > news:O%23x$J4pqGHA.3380@TK2MSFTNGP04.phx.gbl... >> It doesn't matter what DLL the class is in. It's exactly the same. >> >> "vul" <a**@optonline.net> wrote in message >> news:OdbE$ypqGHA.1852@TK2MSFTNGP03.phx.gbl... >>> Thank you, Marina. >>> How do I access shared member from an external program? >>> I wanted to make the property Shared to avoid creating Objects inside of >>> DLL by other Classes and Windows Forms. And inside of DLL this approach >>> works. >>> But I need to access those properties from outside of DLL as well. >>> >>> Al >>> >>> >>> "Marina Levit [MVP]" <someone@nospam.com> wrote in message >>> news:e7VictpqGHA.4408@TK2MSFTNGP04.phx.gbl... >>>> The problem is you are still accessing the property through the object >>>> reference 'obj', which you presumably never instantiate. >>>> >>>> You are supposed to access shared member through the class name. >>>> >>>> Like: COM.MyProp2 >>>> >>>> Additionally, I am not sure why you are calling CreateObject? This is >>>> just a .NET class. Use a constructor if you want an instance of it. >>>> >>>> "Al" <a*@newsgroups.com> wrote in message >>>> news:et$YGnpqGHA.2232@TK2MSFTNGP04.phx.gbl... >>>>> I'd like to create Class Library in VB 2005, which has a property >>>>> accessible by external programs. >>>>> I decided to include 1 Class with 1 property in this project. >>>>> I placed this code in Class: >>>>> Public Class COM >>>>> >>>>> Private mMyProp As String >>>>> >>>>> Public Property MyProp() As String >>>>> >>>>> Get >>>>> >>>>> Return mMyProp >>>>> >>>>> End Get >>>>> >>>>> Set(ByVal value As String) >>>>> >>>>> mMyProp = value >>>>> >>>>> End Set >>>>> >>>>> End Property >>>>> >>>>> End Class >>>>> >>>>> I compiled the project, created another project (Windows Forms) and >>>>> added this code to it: >>>>> Private obj As Object >>>>> Private Sub Command1_Click() >>>>> Set obj = CreateObject("SharedTestDLL.COM") >>>>> obj.MyProp = "Test" >>>>> MsgBox obj.MyProp >>>>> End Sub >>>>> Everything is fine so far. >>>>> >>>>> But I wouldn't want to create an object, so I added for testing >>>>> purposes another Property as Public Shared: >>>>> >>>>> Public Class COM >>>>> >>>>> Private mMyProp As String >>>>> >>>>> Private Shared mMyProp2 As String >>>>> >>>>> Public Property MyProp() As String >>>>> >>>>> Get >>>>> >>>>> Return mMyProp >>>>> >>>>> End Get >>>>> >>>>> Set(ByVal value As String) >>>>> >>>>> mMyProp = value >>>>> >>>>> End Set >>>>> >>>>> End Property >>>>> >>>>> Public Shared Property MyProp2() As String >>>>> >>>>> Get >>>>> >>>>> Return mMyProp2 >>>>> >>>>> End Get >>>>> >>>>> Set(ByVal value As String) >>>>> >>>>> mMyProp2 = value >>>>> >>>>> End Set >>>>> >>>>> End Property >>>>> >>>>> End Class >>>>> >>>>> I also added the code to work with the second property in my client: >>>>> obj.MyProp2 = "Test2" >>>>> MsgBox obj.MyProp2 >>>>> I'm getting an error: >>>>> Object doesn't support this property or method. >>>>> >>>>> Obviously I do not understand Shared stuff. What am I doing wrong? >>>>> I tried the same code with Early Binding and it did not work too. >>>>> >>>>> So, how do I create and use properties without creating an object in >>>>> the client? >>>>> >>>>> Thank you >>>>> Al >>>>> >>>> >>>> >>> >>> >> >> > > I'm trying to use in client:
SharedTestDLL.COM.MyProp2 = "Test2" MsgBox SharedTestDLL.COM.MyProp2 and get an error : Variable not defined. I tried: COM.MyProp2 = "Test2" and MyProp2 = "Test2" with no succes either. Maybe I need to declare some variable first then assign somehow the value, but it looks like creating an object from my DLL class again. And you say I should not do that (create an instance) So, how the code in VB client should look in order to work with MyProp2 property wich is declared as Public Shared inside of DLL's Class? Sorry for my stupidity. Al Show quoteHide quote "Marina Levit [MVP]" <someone@nospam.com> wrote in message news:uQxvdVqqGHA.644@TK2MSFTNGP05.phx.gbl... >I did give you code. If your class name is COM, and the property is named >MySharedProp2, you would just say "COM.MySharedProp2". > > That is all there is. > > If you could create an instance of the class in the other program, then > you can certainly access a shared property. > > It sounds to me like you are missing something else much more basic, > although what that is hard to say with the information you provided. > > "Al" <a*@newsgroups.com> wrote in message > news:uUOrPRqqGHA.3484@TK2MSFTNGP04.phx.gbl... >> Could you give me the code for accessing property in DLL from external >> program (VB client), please. Because I'm still confused. >> Thank you >> Al >> >> "Marina Levit [MVP]" <someone@nospam.com> wrote in message >> news:O%23x$J4pqGHA.3380@TK2MSFTNGP04.phx.gbl... >>> It doesn't matter what DLL the class is in. It's exactly the same. >>> >>> "vul" <a**@optonline.net> wrote in message >>> news:OdbE$ypqGHA.1852@TK2MSFTNGP03.phx.gbl... >>>> Thank you, Marina. >>>> How do I access shared member from an external program? >>>> I wanted to make the property Shared to avoid creating Objects inside >>>> of DLL by other Classes and Windows Forms. And inside of DLL this >>>> approach works. >>>> But I need to access those properties from outside of DLL as well. >>>> >>>> Al >>>> >>>> >>>> "Marina Levit [MVP]" <someone@nospam.com> wrote in message >>>> news:e7VictpqGHA.4408@TK2MSFTNGP04.phx.gbl... >>>>> The problem is you are still accessing the property through the object >>>>> reference 'obj', which you presumably never instantiate. >>>>> >>>>> You are supposed to access shared member through the class name. >>>>> >>>>> Like: COM.MyProp2 >>>>> >>>>> Additionally, I am not sure why you are calling CreateObject? This is >>>>> just a .NET class. Use a constructor if you want an instance of it. >>>>> >>>>> "Al" <a*@newsgroups.com> wrote in message >>>>> news:et$YGnpqGHA.2232@TK2MSFTNGP04.phx.gbl... >>>>>> I'd like to create Class Library in VB 2005, which has a property >>>>>> accessible by external programs. >>>>>> I decided to include 1 Class with 1 property in this project. >>>>>> I placed this code in Class: >>>>>> Public Class COM >>>>>> >>>>>> Private mMyProp As String >>>>>> >>>>>> Public Property MyProp() As String >>>>>> >>>>>> Get >>>>>> >>>>>> Return mMyProp >>>>>> >>>>>> End Get >>>>>> >>>>>> Set(ByVal value As String) >>>>>> >>>>>> mMyProp = value >>>>>> >>>>>> End Set >>>>>> >>>>>> End Property >>>>>> >>>>>> End Class >>>>>> >>>>>> I compiled the project, created another project (Windows Forms) and >>>>>> added this code to it: >>>>>> Private obj As Object >>>>>> Private Sub Command1_Click() >>>>>> Set obj = CreateObject("SharedTestDLL.COM") >>>>>> obj.MyProp = "Test" >>>>>> MsgBox obj.MyProp >>>>>> End Sub >>>>>> Everything is fine so far. >>>>>> >>>>>> But I wouldn't want to create an object, so I added for testing >>>>>> purposes another Property as Public Shared: >>>>>> >>>>>> Public Class COM >>>>>> >>>>>> Private mMyProp As String >>>>>> >>>>>> Private Shared mMyProp2 As String >>>>>> >>>>>> Public Property MyProp() As String >>>>>> >>>>>> Get >>>>>> >>>>>> Return mMyProp >>>>>> >>>>>> End Get >>>>>> >>>>>> Set(ByVal value As String) >>>>>> >>>>>> mMyProp = value >>>>>> >>>>>> End Set >>>>>> >>>>>> End Property >>>>>> >>>>>> Public Shared Property MyProp2() As String >>>>>> >>>>>> Get >>>>>> >>>>>> Return mMyProp2 >>>>>> >>>>>> End Get >>>>>> >>>>>> Set(ByVal value As String) >>>>>> >>>>>> mMyProp2 = value >>>>>> >>>>>> End Set >>>>>> >>>>>> End Property >>>>>> >>>>>> End Class >>>>>> >>>>>> I also added the code to work with the second property in my client: >>>>>> obj.MyProp2 = "Test2" >>>>>> MsgBox obj.MyProp2 >>>>>> I'm getting an error: >>>>>> Object doesn't support this property or method. >>>>>> >>>>>> Obviously I do not understand Shared stuff. What am I doing wrong? >>>>>> I tried the same code with Early Binding and it did not work too. >>>>>> >>>>>> So, how do I create and use properties without creating an object in >>>>>> the client? >>>>>> >>>>>> Thank you >>>>>> Al >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > Sorry, I misled you.
I'm using VB6 client. Probably this is the problem. I just tried to use VB 2005 client and after I added a reference to SharedTestDLL, I got an access to COM class and its shared property. Is Late Binding possible to access that shared property? I have a reason to use VB6 with Late Binding (long explanation) So I need somehow to find the way to work with properties of DLL from VB6 client. I also have a reason to create DLL in VB 2005, not in VB6. Al Show quoteHide quote "Marina Levit [MVP]" <someone@nospam.com> wrote in message news:uQxvdVqqGHA.644@TK2MSFTNGP05.phx.gbl... >I did give you code. If your class name is COM, and the property is named >MySharedProp2, you would just say "COM.MySharedProp2". > > That is all there is. > > If you could create an instance of the class in the other program, then > you can certainly access a shared property. > > It sounds to me like you are missing something else much more basic, > although what that is hard to say with the information you provided. > > "Al" <a*@newsgroups.com> wrote in message > news:uUOrPRqqGHA.3484@TK2MSFTNGP04.phx.gbl... >> Could you give me the code for accessing property in DLL from external >> program (VB client), please. Because I'm still confused. >> Thank you >> Al >> >> "Marina Levit [MVP]" <someone@nospam.com> wrote in message >> news:O%23x$J4pqGHA.3380@TK2MSFTNGP04.phx.gbl... >>> It doesn't matter what DLL the class is in. It's exactly the same. >>> >>> "vul" <a**@optonline.net> wrote in message >>> news:OdbE$ypqGHA.1852@TK2MSFTNGP03.phx.gbl... >>>> Thank you, Marina. >>>> How do I access shared member from an external program? >>>> I wanted to make the property Shared to avoid creating Objects inside >>>> of DLL by other Classes and Windows Forms. And inside of DLL this >>>> approach works. >>>> But I need to access those properties from outside of DLL as well. >>>> >>>> Al >>>> >>>> >>>> "Marina Levit [MVP]" <someone@nospam.com> wrote in message >>>> news:e7VictpqGHA.4408@TK2MSFTNGP04.phx.gbl... >>>>> The problem is you are still accessing the property through the object >>>>> reference 'obj', which you presumably never instantiate. >>>>> >>>>> You are supposed to access shared member through the class name. >>>>> >>>>> Like: COM.MyProp2 >>>>> >>>>> Additionally, I am not sure why you are calling CreateObject? This is >>>>> just a .NET class. Use a constructor if you want an instance of it. >>>>> >>>>> "Al" <a*@newsgroups.com> wrote in message >>>>> news:et$YGnpqGHA.2232@TK2MSFTNGP04.phx.gbl... >>>>>> I'd like to create Class Library in VB 2005, which has a property >>>>>> accessible by external programs. >>>>>> I decided to include 1 Class with 1 property in this project. >>>>>> I placed this code in Class: >>>>>> Public Class COM >>>>>> >>>>>> Private mMyProp As String >>>>>> >>>>>> Public Property MyProp() As String >>>>>> >>>>>> Get >>>>>> >>>>>> Return mMyProp >>>>>> >>>>>> End Get >>>>>> >>>>>> Set(ByVal value As String) >>>>>> >>>>>> mMyProp = value >>>>>> >>>>>> End Set >>>>>> >>>>>> End Property >>>>>> >>>>>> End Class >>>>>> >>>>>> I compiled the project, created another project (Windows Forms) and >>>>>> added this code to it: >>>>>> Private obj As Object >>>>>> Private Sub Command1_Click() >>>>>> Set obj = CreateObject("SharedTestDLL.COM") >>>>>> obj.MyProp = "Test" >>>>>> MsgBox obj.MyProp >>>>>> End Sub >>>>>> Everything is fine so far. >>>>>> >>>>>> But I wouldn't want to create an object, so I added for testing >>>>>> purposes another Property as Public Shared: >>>>>> >>>>>> Public Class COM >>>>>> >>>>>> Private mMyProp As String >>>>>> >>>>>> Private Shared mMyProp2 As String >>>>>> >>>>>> Public Property MyProp() As String >>>>>> >>>>>> Get >>>>>> >>>>>> Return mMyProp >>>>>> >>>>>> End Get >>>>>> >>>>>> Set(ByVal value As String) >>>>>> >>>>>> mMyProp = value >>>>>> >>>>>> End Set >>>>>> >>>>>> End Property >>>>>> >>>>>> Public Shared Property MyProp2() As String >>>>>> >>>>>> Get >>>>>> >>>>>> Return mMyProp2 >>>>>> >>>>>> End Get >>>>>> >>>>>> Set(ByVal value As String) >>>>>> >>>>>> mMyProp2 = value >>>>>> >>>>>> End Set >>>>>> >>>>>> End Property >>>>>> >>>>>> End Class >>>>>> >>>>>> I also added the code to work with the second property in my client: >>>>>> obj.MyProp2 = "Test2" >>>>>> MsgBox obj.MyProp2 >>>>>> I'm getting an error: >>>>>> Object doesn't support this property or method. >>>>>> >>>>>> Obviously I do not understand Shared stuff. What am I doing wrong? >>>>>> I tried the same code with Early Binding and it did not work too. >>>>>> >>>>>> So, how do I create and use properties without creating an object in >>>>>> the client? >>>>>> >>>>>> Thank you >>>>>> Al >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > >
Show quote
Hide quote
"Al" <a*@newsgroups.com> schrieb: I am wondering why you are using 'CreateObject' instead of 'New > I'd like to create Class Library in VB 2005, which has a property > accessible by external programs. > I decided to include 1 Class with 1 property in this project. > I placed this code in Class: > Public Class COM > > Private mMyProp As String > > Public Property MyProp() As String > > Get > > Return mMyProp > > End Get > > Set(ByVal value As String) > > mMyProp = value > > End Set > > End Property > > End Class > > I compiled the project, created another project (Windows Forms) and added > this code to it: > Private obj As Object > Private Sub Command1_Click() > Set obj = CreateObject("SharedTestDLL.COM") SharedTestDLL.COM'. > But I wouldn't want to create an object, so I added for testing purposes Your property declaration is lacking the 'Shared' keyword.> another Property as Public Shared: > > Public Class COM > > Private mMyProp As String > > Private Shared mMyProp2 As String > > Public Property MyProp() As String > I also added the code to work with the second property in my client: Type 'obj' as 'COM' instead of 'Object'.> obj.MyProp2 = "Test2" > MsgBox obj.MyProp2 > I'm getting an error: > Object doesn't support this property or method. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Barcode scanning
String comparison algorithms ByRef - delayed update of the original variable? The RPC Server is unavailable! Moving toolbox Editing Data SorteList Comparer: how to change it on the fly? Dataset.HasChangesmethod ? Read & WriteMemoryProcess (Adress Space) Problem VB.NET counterpart to the java URL Class |
|||||||||||||||||||||||