Property Get, Property Let functions

pkh

New Member
Joined
Nov 23, 2011
Messages
21
Hi,

I am trying to understand Class objects and have the following question regarding Property Get and Property Let functions.

Functionally, it seems they are just assigning or obtaining values for the property variables. Why can't we just assign them directly as values to variables instead of putting them through the Property Get (or Let)........Property End code.

In the examples I have seen, for eg.
Code:
Private pName as String
 
Public Property Get Name () As String
       Name = pName
End Property
 
Public Property Let Name (Value As String)
        pName = Value
End Property
' these examples are from C Pearson's VBA lessons

Why not just use:

Code:
Private pName as String
 
Sub WhateverCode()
Dim Name as String
Name=pName
pName = pkh
End Sub

Thanks,
pkh
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
1. It allows you to do validation of the values.
2. How is your second code better/different, as it doesn't allow you to pass a value?

The idea is that your class behaves like other objects in VBA, so you can use:
Code:
myObj.Name = "blah"
 
Upvote 0
Rory,

Thanks for the explanation. I see what you mean. Classes and their attendent procedures have been bit of a learning curve for me.

pk
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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