Function v Get Property

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,924
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
What's the difference between a function and the Get Property?

Both TestFunction and TestProperty generate the same results.

Code:
Option Explicit

Sub TestFunction()

    Dim d As Long
    
    d = MyFunction(1, 2, 3)

End Sub


Sub TestProperty()

    Dim d As Long
    
    d = MyProperty(1, 2, 3)

End Sub

Function MyFunction(a, b, c) As Long

    MyFunction = a + b + c

End Function


Property Get MyProperty(a, b, c) As Long

    MyProperty = a + b + c
    
End Property

Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
As long as you don't need to pass any arguments ByRef, nothing really. It's a little unusual to have a property that requires any arguments, and certainly not 3.
 
Upvote 0
Thanks.

(And if you do have to pass args, then the difference is that Properties always pass ByVal, (as you said in my other post), whereas Functions can be either)?
 
Last edited:
Upvote 0
The main difference isn't in the Property Get, but the Property Let/Set.

If you are going to be setting the value as well as fetching it, Property Get / Property Set is the best way to go. Although you could use a function and a sub instead.
 
Upvote 0
(And if you do have to pass args, then the difference is that Properties always pass ByVal, (as you said in my other post), whereas Functions can be either)?

That's correct.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top