Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Class Properties

Class Properties

Scheduled Pinned Locked Moved Visual Basic
question
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rahvyn6
    wrote on last edited by
    #1

    I have a class, class A. Within that class are defined multiple properties. (Gets and Sets). In the same project, I have a second class file, Class B. Class A's properties are public, but I am unable to access them from Class B, and when I try to pass Class A into Class B, it doesnt allow it, saying "Class A is a type and cannot be used as an expression". Not sure what I need to do to make Class A Accessible within Class B. Can anyone point me to where I need to go? Thanks

    C 1 Reply Last reply
    0
    • R rahvyn6

      I have a class, class A. Within that class are defined multiple properties. (Gets and Sets). In the same project, I have a second class file, Class B. Class A's properties are public, but I am unable to access them from Class B, and when I try to pass Class A into Class B, it doesnt allow it, saying "Class A is a type and cannot be used as an expression". Not sure what I need to do to make Class A Accessible within Class B. Can anyone point me to where I need to go? Thanks

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      What you need to do is post code. Best guess - you are trying to access them as ClassA.SomeProperty when they are not static. YOu need a class instance ( which holds the value for thqat instance only ) or to make them static ( which I think is Shared in VB )

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      R 1 Reply Last reply
      0
      • C Christian Graus

        What you need to do is post code. Best guess - you are trying to access them as ClassA.SomeProperty when they are not static. YOu need a class instance ( which holds the value for thqat instance only ) or to make them static ( which I think is Shared in VB )

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        R Offline
        R Offline
        rahvyn6
        wrote on last edited by
        #3

        Here is what I have, in Class A: Public Class ClassA Private Shared propName As String Public Shared Property strPropName() As String Get Return propName End Get Set(ByVal value As String) propName = value End Set End Property End Class That will allow me to access it as a property directly within another class. (Thanks) However, these properties are set from a VB6 application, which then calls different methods within Class B. I can access the properties in Class B now, but they are not visible in the VB6 app anymore. I have the project setup for Com Interop, and can see everything else, just not the properties I set this way. Am I stuck with one or the other? Or is there a way to get both? I found that if I change the Public Shared Property to just Public Property, I can see it in the vb6 app, but not in the other classes within the project.

        C 1 Reply Last reply
        0
        • R rahvyn6

          Here is what I have, in Class A: Public Class ClassA Private Shared propName As String Public Shared Property strPropName() As String Get Return propName End Get Set(ByVal value As String) propName = value End Set End Property End Class That will allow me to access it as a property directly within another class. (Thanks) However, these properties are set from a VB6 application, which then calls different methods within Class B. I can access the properties in Class B now, but they are not visible in the VB6 app anymore. I have the project setup for Com Interop, and can see everything else, just not the properties I set this way. Am I stuck with one or the other? Or is there a way to get both? I found that if I change the Public Shared Property to just Public Property, I can see it in the vb6 app, but not in the other classes within the project.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          rahvyn6 wrote:

          Or is there a way to get both? I found that if I change the Public Shared Property to just Public Property, I can see it in the vb6 app, but not in the other classes within the project.

          Sounds like you can have one or the other. There's no way to do it without having something shared at some point. One possible hack is to have a non shared property which, when called, sets or gets the shared one. So, you have a non shared property, which turns out to really be shared.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          R 1 Reply Last reply
          0
          • C Christian Graus

            rahvyn6 wrote:

            Or is there a way to get both? I found that if I change the Public Shared Property to just Public Property, I can see it in the vb6 app, but not in the other classes within the project.

            Sounds like you can have one or the other. There's no way to do it without having something shared at some point. One possible hack is to have a non shared property which, when called, sets or gets the shared one. So, you have a non shared property, which turns out to really be shared.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            R Offline
            R Offline
            rahvyn6
            wrote on last edited by
            #5

            That would be a major pain, I have around 150 properties. :wtf:

            C L 2 Replies Last reply
            0
            • R rahvyn6

              That would be a major pain, I have around 150 properties. :wtf:

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Sure - I'm afraid I have no other suggestions.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

              1 Reply Last reply
              0
              • R rahvyn6

                That would be a major pain, I have around 150 properties. :wtf:

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Try using a Module.


                Extreme Exe

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups