By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,743 Members | 1,122 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,743 IT Pros & Developers. It's quick & easy.

Public Shared Property

P: n/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
Jul 18 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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" <al@newsgroups.comwrote in message
news:et**************@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

Jul 18 '06 #2

P: n/a
vul
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]" <so*****@nospam.comwrote in message
news:e7**************@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" <al@newsgroups.comwrote in message
news:et**************@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


Jul 18 '06 #3

P: n/a
It doesn't matter what DLL the class is in. It's exactly the same.

"vul" <aa*@optonline.netwrote in message
news:Od**************@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]" <so*****@nospam.comwrote in message
news:e7**************@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" <al@newsgroups.comwrote in message
news:et**************@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



Jul 18 '06 #4

P: n/a
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

"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:O%****************@TK2MSFTNGP04.phx.gbl...
It doesn't matter what DLL the class is in. It's exactly the same.

"vul" <aa*@optonline.netwrote in message
news:Od**************@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]" <so*****@nospam.comwrote in message
news:e7**************@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" <al@newsgroups.comwrote in message
news:et**************@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



Jul 18 '06 #5

P: n/a
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" <al@newsgroups.comwrote in message
news:uU**************@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]" <so*****@nospam.comwrote in message
news:O%****************@TK2MSFTNGP04.phx.gbl...
>It doesn't matter what DLL the class is in. It's exactly the same.

"vul" <aa*@optonline.netwrote in message
news:Od**************@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]" <so*****@nospam.comwrote in message
news:e7**************@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" <al@newsgroups.comwrote in message
news:et**************@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
>




Jul 18 '06 #6

P: n/a
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


"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:uQ*************@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" <al@newsgroups.comwrote in message
news:uU**************@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]" <so*****@nospam.comwrote in message
news:O%****************@TK2MSFTNGP04.phx.gbl...
>>It doesn't matter what DLL the class is in. It's exactly the same.

"vul" <aa*@optonline.netwrote in message
news:Od**************@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]" <so*****@nospam.comwrote in message
news:e7**************@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" <al@newsgroups.comwrote in message
news:et**************@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
>>
>
>




Jul 18 '06 #7

P: n/a
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

"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:uQ*************@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" <al@newsgroups.comwrote in message
news:uU**************@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]" <so*****@nospam.comwrote in message
news:O%****************@TK2MSFTNGP04.phx.gbl...
>>It doesn't matter what DLL the class is in. It's exactly the same.

"vul" <aa*@optonline.netwrote in message
news:Od**************@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]" <so*****@nospam.comwrote in message
news:e7**************@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" <al@newsgroups.comwrote in message
news:et**************@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
>>
>
>




Jul 18 '06 #8

P: n/a
"Al" <al@newsgroups.comschrieb:
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")
I am wondering why you are using 'CreateObject' instead of 'New
SharedTestDLL.COM'.
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
Your property declaration is lacking the 'Shared' keyword.
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.
Type 'obj' as 'COM' instead of 'Object'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jul 18 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.