Results 1 to 5 of 5

Thread: Methods of a property

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    Methods of a property

    This is a really silly question... but today I wrote a class which has a property which can be formatted in different ways. I have also written various subs in the class that formats a string (the property exposes a private string)....

    if I want to access the methods like this:


    myObject.MyProperty.MyMethod


    How do I code this?

    kind regards
    henrik - thinking he has a total blackout and need to go back to vb.net 101

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    If your property points to a class, just make a public sub inside the class.

    e.g. Public Property MyProp as MyClass

    Then just have the sub in MyClass.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Here's a small sample that I hope you find usefull.

    VB Code:
    1. Public Class My_Class
    2.  
    3.     Dim m_MyPropClass As New MyPropClass()
    4.  
    5.     Public Property MyProperty() As MyPropClass
    6.         Get
    7.             Return m_MyPropClass
    8.         End Get
    9.         Set(ByVal Value As MyPropClass)
    10.             m_MyPropClass = Value
    11.         End Set
    12.     End Property
    13. End Class
    14.  
    15. Public Class MyPropClass
    16.  
    17.     Public Sub ShowMessage()
    18.         MsgBox("Message Shown")
    19.     End Sub
    20. End Class
    21.  
    22.  
    23. 'Usage...
    24.     Dim A As New My_Class()
    25.  
    26.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    27.         A.MyProperty.ShowMessage()
    28.  
    29.     End Sub
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    okay thanks... I don't know where my thoughts wandered


    kind regards
    Henrik

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    It's very comforting to know that even you guys have a Brain.System crash occasionally
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width