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 theory, what am I missing

Class theory, what am I missing

Scheduled Pinned Locked Moved Visual Basic
questioncsharpvisual-studiocom
4 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.
  • J Offline
    J Offline
    Justin Porteous
    wrote on last edited by
    #1

    Good day fellow codeproject.com'ers. I am missing a vital part of theory which I've identified when I tried the below. (I believe it's theory...) Please can one of you assist me by filling the theory gap I have. I've been through MSDN and Google, but to no avail... Question: Why can one not call a class from within another class? I don't mean within a function of a class, but at the top, where one declares variables pertaining to that class. E.g. Below:

    Friend Class Class1
    Dim _message As String

    Public Property Message()
        Get
            Return \_message
        End Get
        Set(ByVal value)
            \_message = value
        End Set
    End Property
    

    End Class

    And here is where it fails, intellisense doesn't see the properties or methods of the variable (first class), I've labled the variable as THISDOESNTWORK.

    Friend Class Class2
    Dim _myVariable As String
    Dim THISDOESNTWORK as New Class1

    Public Property myVariable()
        Get
            Return \_message
        End Get
        Set(ByVal value)
            \_message = value
        End Set
    End Property
    

    End Class

    It works when I place the code Dim THISDOESNTWORK as New Class1 within a function, so either there is a "secret way to do this", or I'm missing a bit of .Net/OOB Theory. Thanks in advance... :)

    N 1 Reply Last reply
    0
    • J Justin Porteous

      Good day fellow codeproject.com'ers. I am missing a vital part of theory which I've identified when I tried the below. (I believe it's theory...) Please can one of you assist me by filling the theory gap I have. I've been through MSDN and Google, but to no avail... Question: Why can one not call a class from within another class? I don't mean within a function of a class, but at the top, where one declares variables pertaining to that class. E.g. Below:

      Friend Class Class1
      Dim _message As String

      Public Property Message()
          Get
              Return \_message
          End Get
          Set(ByVal value)
              \_message = value
          End Set
      End Property
      

      End Class

      And here is where it fails, intellisense doesn't see the properties or methods of the variable (first class), I've labled the variable as THISDOESNTWORK.

      Friend Class Class2
      Dim _myVariable As String
      Dim THISDOESNTWORK as New Class1

      Public Property myVariable()
          Get
              Return \_message
          End Get
          Set(ByVal value)
              \_message = value
          End Set
      End Property
      

      End Class

      It works when I place the code Dim THISDOESNTWORK as New Class1 within a function, so either there is a "secret way to do this", or I'm missing a bit of .Net/OOB Theory. Thanks in advance... :)

      N Offline
      N Offline
      nlarson11
      wrote on last edited by
      #2

      class2 needs to be like this

      Friend Class Class2
      Dim _myVariable As String
      Dim THISDOESNTWORK As New Class1
      Public Property myVariable()
      Get
      Return THISDOESNTWORK.Message
      End Get
      Set(ByVal value)
      THISDOESNTWORK.Message = value
      End Set
      End Property
      End Class

      'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous

      J 1 Reply Last reply
      0
      • N nlarson11

        class2 needs to be like this

        Friend Class Class2
        Dim _myVariable As String
        Dim THISDOESNTWORK As New Class1
        Public Property myVariable()
        Get
        Return THISDOESNTWORK.Message
        End Get
        Set(ByVal value)
        THISDOESNTWORK.Message = value
        End Set
        End Property
        End Class

        'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous

        J Offline
        J Offline
        Justin Porteous
        wrote on last edited by
        #3

        Thank you! Ah, a blonde moment of note! This one will definatly go down in the books a silly moment for me, hopefully this helps someone else :) Thanks again. - Artificial intelligence is no match for natural stupidity

        T 1 Reply Last reply
        0
        • J Justin Porteous

          Thank you! Ah, a blonde moment of note! This one will definatly go down in the books a silly moment for me, hopefully this helps someone else :) Thanks again. - Artificial intelligence is no match for natural stupidity

          T Offline
          T Offline
          Thomas Stockwell
          wrote on last edited by
          #4

          It should also be mentioned that your syntax might be a bit off: Friend Class Class2 Dim _myVariable As String Dim THISDOESNTWORK as New Class1 Public Property myVariable()as string Get Return THISDOESNTWORK._message End Get Set(ByVal value as string) THISDOESNTWORK._message = value End Set End Property End Class or Friend Class Class2 Dim _myVariable As String Dim THISDOESNTWORK as New Class1 Public Property myVariable() as Class1 Get Return THISDOESNTWORK End Get Set(ByVal value as Class 1) THISDOESNTWORK= value End Set End Property End Class

          Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my Blog

          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