Results 1 to 2 of 2

Thread: [RESOLVED] Property vs Function in Class Module

  1. #1

    Thread Starter
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Resolved [RESOLVED] Property vs Function in Class Module

    In a User-Defined Class:
    For "derived" properties, rather than base properties, is there any difference between coding these as properties or coding them as functions.

    e.g. is there any advantage to using the "Area" property versus the "Area2" function in the following? Or visa versa?


    VB Code:
    1. Option Explicit
    2.  
    3. Private pLGH As Long
    4. Private pHGT As Long
    5.  
    6. 'base properties - lets and gets
    7. Public Property Let Length(newLength As Long)
    8.     pLGH = newLength
    9. End Property
    10.  
    11. Public Property Let Height(newHeight As Long)
    12.     pHGT = newHeight
    13. End Property
    14.  
    15. Public Property Get Length() As Long
    16.     Length = pLGH
    17. End Property
    18.  
    19. Public Property Get Height() As Long
    20.     Height = pHGT
    21. End Property
    22.  
    23.  
    24. 'derived property - using property
    25. Public Property Get Area() As Long
    26.     Area = pLGH * pHGT
    27. End Property
    28.  
    29. 'derived property - using function
    30. Public Function Area2() As Long
    31.     Area2 = pLGH * pHGT
    32. End Function
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  2. #2
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: Property vs Function in Class Module

    there is nothing wrong with either -

    If it's going to be a read-only return value that either is fine.

    If you need to be able to save a value back, Properties would be the better.

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