Public Shared Property

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Al

    #1

    Public Shared Property

    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("S haredTestDLL.CO M")
    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


  • Marina Levit [MVP]

    #2
    Re: Public Shared Property

    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$YGnpqGH A.2232@TK2MSFTN GP04.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("S haredTestDLL.CO M")
    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
    >

    Comment

    • vul

      #3
      Re: Public Shared Property

      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 .comwrote in message
      news:e7VictpqGH A.4408@TK2MSFTN GP04.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$YGnpqGH A.2232@TK2MSFTN GP04.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("S haredTestDLL.CO M")
      > 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
      >>
      >
      >

      Comment

      • Marina Levit [MVP]

        #4
        Re: Public Shared Property

        It doesn't matter what DLL the class is in. It's exactly the same.

        "vul" <aaa@optonline. netwrote in message
        news:OdbE$ypqGH A.1852@TK2MSFTN GP03.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 .comwrote in message
        news:e7VictpqGH A.4408@TK2MSFTN GP04.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$YGnpqG HA.2232@TK2MSFT NGP04.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("S haredTestDLL.CO M")
        >> 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
        >>>
        >>
        >>
        >
        >

        Comment

        • Al

          #5
          Re: Public Shared Property

          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 .comwrote in message
          news:O%23x$J4pq GHA.3380@TK2MSF TNGP04.phx.gbl. ..
          It doesn't matter what DLL the class is in. It's exactly the same.
          >
          "vul" <aaa@optonline. netwrote in message
          news:OdbE$ypqGH A.1852@TK2MSFTN GP03.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 .comwrote in message
          >news:e7VictpqG HA.4408@TK2MSFT NGP04.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
          >>>
          >>Additionall y, 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$YGnpq GHA.2232@TK2MSF TNGP04.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("S haredTestDLL.CO M")
          >>> 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
          >>>>
          >>>
          >>>
          >>
          >>
          >
          >

          Comment

          • Marina Levit [MVP]

            #6
            Re: Public Shared Property

            I did give you code. If your class name is COM, and the property is named
            MySharedProp2, you would just say "COM.MySharedPr op2".

            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:uUOrPRqqGH A.3484@TK2MSFTN GP04.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 .comwrote in message
            news:O%23x$J4pq GHA.3380@TK2MSF TNGP04.phx.gbl. ..
            >It doesn't matter what DLL the class is in. It's exactly the same.
            >>
            >"vul" <aaa@optonline. netwrote in message
            >news:OdbE$ypqG HA.1852@TK2MSFT NGP03.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 .comwrote in message
            >>news:e7Victpq GHA.4408@TK2MSF TNGP04.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$YGnp qGHA.2232@TK2MS FTNGP04.phx.gbl ...
            >>>>I'd like to create Class Library in VB 2005, which has a property
            >>>>accessibl e 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("S haredTestDLL.CO M")
            >>>> obj.MyProp = "Test"
            >>>> MsgBox obj.MyProp
            >>>>End Sub
            >>>>Everythin g 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
            >>>>>
            >>>>
            >>>>
            >>>
            >>>
            >>
            >>
            >
            >

            Comment

            • Al

              #7
              Re: Public Shared Property

              I'm trying to use in client:
              SharedTestDLL.C OM.MyProp2 = "Test2"
              MsgBox SharedTestDLL.C OM.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]" <someone@nospam .comwrote in message
              news:uQxvdVqqGH A.644@TK2MSFTNG P05.phx.gbl...
              >I did give you code. If your class name is COM, and the property is named
              >MySharedProp 2, you would just say "COM.MySharedPr op2".
              >
              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:uUOrPRqqGH A.3484@TK2MSFTN GP04.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 .comwrote in message
              >news:O%23x$J4p qGHA.3380@TK2MS FTNGP04.phx.gbl ...
              >>It doesn't matter what DLL the class is in. It's exactly the same.
              >>>
              >>"vul" <aaa@optonline. netwrote in message
              >>news:OdbE$ypq GHA.1852@TK2MSF TNGP03.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 .comwrote in message
              >>>news:e7Victp qGHA.4408@TK2MS FTNGP04.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
              >>>>>
              >>>>Additionall y, 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$YGn pqGHA.2232@TK2M SFTNGP04.phx.gb l...
              >>>>>I'd like to create Class Library in VB 2005, which has a property
              >>>>>accessib le 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(ByVa l 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("S haredTestDLL.CO M")
              >>>>> obj.MyProp = "Test"
              >>>>> MsgBox obj.MyProp
              >>>>>End Sub
              >>>>>Everythi ng 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(ByVa l value As String)
              >>>>>>
              >>>>>mMyProp = value
              >>>>>>
              >>>>>End Set
              >>>>>>
              >>>>>End Property
              >>>>>>
              >>>>>Public Shared Property MyProp2() As String
              >>>>>>
              >>>>>Get
              >>>>>>
              >>>>>Return mMyProp2
              >>>>>>
              >>>>>End Get
              >>>>>>
              >>>>>Set(ByVa l 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.
              >>>>>>
              >>>>>Obviousl y 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
              >>>>>>
              >>>>>
              >>>>>
              >>>>
              >>>>
              >>>
              >>>
              >>
              >>
              >
              >

              Comment

              • Al

                #8
                Re: Public Shared Property

                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]" <someone@nospam .comwrote in message
                news:uQxvdVqqGH A.644@TK2MSFTNG P05.phx.gbl...
                >I did give you code. If your class name is COM, and the property is named
                >MySharedProp 2, you would just say "COM.MySharedPr op2".
                >
                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:uUOrPRqqGH A.3484@TK2MSFTN GP04.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 .comwrote in message
                >news:O%23x$J4p qGHA.3380@TK2MS FTNGP04.phx.gbl ...
                >>It doesn't matter what DLL the class is in. It's exactly the same.
                >>>
                >>"vul" <aaa@optonline. netwrote in message
                >>news:OdbE$ypq GHA.1852@TK2MSF TNGP03.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 .comwrote in message
                >>>news:e7Victp qGHA.4408@TK2MS FTNGP04.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
                >>>>>
                >>>>Additionall y, 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$YGn pqGHA.2232@TK2M SFTNGP04.phx.gb l...
                >>>>>I'd like to create Class Library in VB 2005, which has a property
                >>>>>accessib le 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(ByVa l 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("S haredTestDLL.CO M")
                >>>>> obj.MyProp = "Test"
                >>>>> MsgBox obj.MyProp
                >>>>>End Sub
                >>>>>Everythi ng 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(ByVa l value As String)
                >>>>>>
                >>>>>mMyProp = value
                >>>>>>
                >>>>>End Set
                >>>>>>
                >>>>>End Property
                >>>>>>
                >>>>>Public Shared Property MyProp2() As String
                >>>>>>
                >>>>>Get
                >>>>>>
                >>>>>Return mMyProp2
                >>>>>>
                >>>>>End Get
                >>>>>>
                >>>>>Set(ByVa l 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.
                >>>>>>
                >>>>>Obviousl y 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
                >>>>>>
                >>>>>
                >>>>>
                >>>>
                >>>>
                >>>
                >>>
                >>
                >>
                >
                >

                Comment

                • Herfried K. Wagner [MVP]

                  #9
                  Re: Public Shared Property

                  "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("S haredTestDLL.CO M")
                  I am wondering why you are using 'CreateObject' instead of 'New
                  SharedTestDLL.C OM'.
                  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/>

                  Comment

                  Working...