tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,926
- Office Version
- 365
- 2019
- Platform
- Windows
Is it better to use properties to pass parameters in a class, (as in Method 1 below) or not?
Method 1:
Sheet1:
ClsUpdateTable
Method 2:
Thanks
Method 1:
Sheet1:
Rich (BB code):
Private Sub UpdateTable()
Dim MyUpdateTable As ClsUpdateTable
Set MyUpdateTable = New ClsUpdateTable
Set MyUpdateTable.Period = Me.Range("Now")
Call MyUpdateTable.UpdateTable
End Sub
ClsUpdateTable
Rich (BB code):
Option Explicit
Private pPeriod As Range
Public Property Get Period() As Range
Set Period = pPeriod
End Property
Public Property Set Period(ByVal P As Range)
Set pPeriod = P
End Property
Sub UpdateTables()
Dim MyArray() As Variant
MyArray = Array("1", "2", "3")
Dim MyArrayElement As Variant
For Each MyArrayElement In MyArray()
Range(Period.Address).Value = MyArrayElement
Next MyArrayElement
End Sub
Method 2:
Sheet1:
ClsUpdateTable
Rich (BB code):
Private Sub UpdateTable()
Dim MyUpdateTable As ClsUpdateTable
Set MyUpdateTable = New ClsUpdateTable
Call MyUpdateTable.UpdateTable(Period:=Me.Range("Now"))
End Sub
ClsUpdateTable
Rich (BB code):
Option Explicit
Sub UpdateTables(ByRef Period As Range)
Dim MyArray() As Variant
MyArray = Array("1", "2", "3")
Dim MyArrayElement As Variant
For Each MyArrayElement In MyArray()
Range(Period.Address).Value = MyArrayElement
Next MyArrayElement
End Sub
Thanks
Last edited: