79320382

Date: 2024-12-31 16:21:17
Score: 0.5
Natty:
Report link

I did a fun experiment, a custom class with two ways of setting the range that it contains

Option Explicit
Private rg As Range
Property Let rg_let(r As Range)
    Set rg = r
End Property
Property Set rg_set(r As Range)
    Set rg = r
End Property
Property Get rg_out() As Range
    Set rg_out = rg
End Property

and then a routine that passes the range in two different ways and gets sensible results in both cases. Using the Let version seems rather neater...

Sub test()
    Dim x As cl_spj
    Set x = New cl_spj
' just pass the range pointer as an argument, which the property then processes
    x.rg_let = Range("a2")
    debug.print "Let " & x.rg_out.Address
' pass the range using set
    Set x.rg_set = Range("a3")
    debug.print "Set " & x.rg_out.Address
End Sub
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Simon J