A
Al
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
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