Conceptually speaking, is there any reason to have a private variable in VBA since there is no true object-orientated functionality with VBA?
I've been building this project that includes many user-defined classes with many private variables. I'm second-guessing the structure of my project and wondering if the extra time I spent creating Get/Let methods are all but an exercise in good programming practices. If you would like, take a quick glance at the structure of one of my user-defined classes to help answer my question...any thoughts are appreciated.
The following is a User-defined class that is used to build another one of my User-defined classes: CTradeSpread. I use CTradeSpread to store hundreds of Stock Option Contract Trades that are described in a spreadsheet that is downloaded from a broker's Account Trading History.
Option Explicit
'/These variables are obtained in ATH (Account Trade History) & CB (Cash Balance) section of the broker's spreadsheet of trades
Private pLegSymbol As String 'ticker symbol of each leg
Private pLegStrike As Double 'strike of option contract
Private pLegExp As String 'expiration date (month and year)
Private pLegType As String 'Call or Put or Stock
Private pLegQTY As Integer 'QTY of option contracts
Private pLegSpread As String 'VERTICAL, SINGLE, etc. (note: pLegSpread never changes and may be different than CTradeSpread's Private Variable: Spread
'/These variables are read-only and derived from other private variables
Private pLegExpirationDay As Date 'Output of CDateOperations.(pLegExp)
Private pLegExpirationPrice As Double 'Price of Underlying at expiration
Private pHasLegExpired As Boolean 'True if Now() is before LegExpirationDay
'/These variables are found in ATH only
Private pATHLine As Integer
Private pLegPosEffATH As String 'to open or to close (used to determine .Purpose: "TO OPEN", "TO CLOSE", OR "TO ADJUST" (TO ADJUST when legs are a mix of "TO OPEN" and "TO CLOSE")
Private pAMTi As Double 'amount per leg
'/These variables are found in CB only
Private pCBLine As Integer
Private pContractMultipleCB As Integer
'/Read-Only Variables
Private pNumberOfAdjustments As Integer
Private pNumberOfLegIns As Integer
Private pNumberOfLegOuts As Integer
'/Undeveloped -- may be taken from ATH
Private pEM As String 'Execution Method (MKT, LMT, etc.)
'/These variables are populated as a sequence of trades is built
Private pReferenceNumberCollection As Collection
Private pDatesOfExecutionCollection As Collection
Private pTimesOfExecutionCollection As Collection
Private Function GetPriceOfStock(DateOfPrice As Date) As Double
Dim LastTradingDate As Date
Dim DateOperator As CDateOperations
Set DateOperator = New CDateOperations
'/Data Validation
'/Verify Date is not in future, Expiration & Symbol are set, and the date is not after the expiration date
If pLegSymbol = Empty Then
MsgBox ("Error in Class CLeg, Function GetPriceOfStock: Symbol of Leg is not set" & vbCr & "This is possibly a new instance of CLeg")
Else
If DateOfPrice > Now() Then MsgBox ("Error in Class CLeg, Function GetPriceOfStock: DateOfPrice is in the future")
If pLegExp = Empty Then
MsgBox ("Error in Class CLeg, Function GetPriceOfStock: Expiration of Leg is not set but Symbol is" & vbCr & "This is possibly an undeveloped instance of CLeg")
Else
LastTradingDate = DateOperator.SettlementDateOrExpirationDescriptionToLastTradingDay(pLegExp)
End If
If LastTradingDate < DateOfPrice Then MsgBox ("Error in Class CLeg, Function GetPriceOfStock: DateOfPrice is after expiration's last trading day")
End If
'/Undeveloped code goes here
End Function
Public Property Get HasLegExpired() As Boolean
If Now() < pLegExpirationDay Then
pHasLegExpired = False
Else
pHasLegExpired = True
End If
HasLegExpired = pHasLegExpired
End Property
Public Property Get LegExpirationDay()
Dim OperateOnDate As CDateOperations
Set OperateOnDate = New CDateOperations
If pLegExp <> Empty Then 'replaced "" w/ Empty
pLeogExpirationDay = OperateOnDate.SettlementDateOrExpirationDescriptionToLastTradingDay(pLegExp)
'pLegExpirationDay = OperateOnDate.SettlementDateOrExpirationDate(pLegExp) 'method has been changed
LegExpirationDay = pLegExpirationDay
End If
End Property
Public Property Get DatesOfExecutionCollection() As Collection
If pDatesOfExecutionCollection Is Nothing Then Set pDatesOfExecutionCollection = New Collection
Set DatesOfExecutionCollection = pDatesOfExecutionCollection
End Property
Public Property Let DatesOfExecutionCollection(Value As Collection)
If pDatesOfExecutionCollection Is Nothing Then Set pDatesOfExecutionCollection = New Collection
Set pDatesOfExecutionCollection = Value
End Property
Public Function AddDatesOfExecutionToLeg(Value As Date)
If pDatesOfExecutionCollection Is Nothing Then Set pDatesOfExecutionCollection = New Collection
pDatesOfExecutionCollection.Add CDate(Format(Value, "m/d/yyyy"))
End Function
Public Property Get TimesOfExecutionCollection() As Collection
If pTimesOfExecutionCollection Is Nothing Then Set pTimesOfExecutionCollection = New Collection
Set TimesOfExecutionCollection = pTimesOfExecutionCollection
End Property
Public Property Let TimesOfExecutionCollection(Value As Collection)
If pTimesOfExecutionCollection Is Nothing Then Set pTimesOfExecutionCollection = New Collection
Set pTimesOfExecutionCollection = Value
End Property
Public Function AddTimesOfExecutionToLeg(Value As Date)
If pTimesOfExecutionCollection Is Nothing Then Set pTimesOfExecutionCollection = New Collection
pTimesOfExecutionCollection.Add Format(Value, "h:m:s")
End Function
Public Property Get ReferenceNumberCollection() As Collection
If pReferenceNumberCollection Is Nothing Then Set pReferenceNumberCollection = New Collection
Set ReferenceNumberCollection = pReferenceNumberCollection
End Property
Public Property Let ReferenceNumberCollection(Value As Collection)
If pReferenceNumberCollection Is Nothing Then Set pReferenceNumberCollection = New Collection
Set pReferenceNumberCollection = Value
End Property
Public Function AddReferenceNumberToLeg(Value As Double)
If pReferenceNumberCollection Is Nothing Then Set pReferenceNumberCollection = New Collection
pReferenceNumberCollection.Add Value
End Function
Public Property Get NumberOfAdjustments() As Integer
NumberOfAdjustments = pNumberOfAdjustments
End Property
Public Property Let NumberOfAdjustments(Value As Integer)
pNumberOfAdjustments = Value
End Property
Public Property Get NumberOfLegIns() As Integer
NumberOfLegIns = pNumberOfLegIns
End Property
Public Property Let NumberOfLegIns(Value As Integer)
pNumberOfLegIns = Value
End Property
Public Property Get NumberOfLegOuts() As Integer
NumberOfLegOuts = pNumberOfLegOuts
End Property
Public Property Let NumberOfLegOuts(Value As Integer)
pNumberOfLegOuts = Value
End Property
'EM''''''''''''''''''''''''''''''''''''''''''' 'Execution Method (MKT, LMT, etc.)
Public Property Get EM() As String
EM = pEM
End Property
Public Property Let EM(Value As String)
pEM = Value
End Property
''''''''''''''''''''''''''''''''''''''''''''''
'Spread''''''''''''''''''''''''''''''''''''''
Public Property Get LegSpread() As String
LegSpread = pLegSpread
End Property
Public Property Let LegSpread(Value As String)
pLegSpread = Value
End Property
Public Property Get AMTi() As Double
AMTi = pAMTi
End Property
Public Property Let AMTi(Value As Double)
pAMTi = Value
End Property
Public Property Get ATHLine() As Integer
ATHLine = pATHLine
End Property
Public Property Let ATHLine(Value As Integer)
pATHLine = Value
End Property
Public Property Get CBLINE() As Integer
CBLINE = pCBLine
End Property
Public Property Let CBLINE(Value As Integer)
pCBLine = Value
End Property
Public Property Get ContractMultipleCB() As Integer
ContractMultipleCB = pContractMultipleCB
End Property
Public Property Let ContractMultipleCB(Value As Integer)
pContractMultipleCB = Value
End Property
Public Property Get LegStrike() As Double
LegStrike = pLegStrike
End Property
Public Property Let LegStrike(Value As Double)
pLegStrike = Value
End Property
Public Property Get LegSymbol() As String
LegSymbol = pLegSymbol
End Property
Public Property Let LegSymbol(Value As String)
pLegSymbol = Value
End Property
Public Property Get LegExp() As String
LegExp = pLegExp
End Property
Public Property Let LegExp(Value As String)
pLegExp = Value
End Property
Public Property Get LegType() As String
LegType = pLegType
End Property
Public Property Let LegType(Value As String)
pLegType = Value
End Property
Public Property Get LegQTY() As Integer
LegQTY = pLegQTY
End Property
Public Property Let LegQTY(Value As Integer)
pLegQTY = Value
End Property
Public Property Get LegPosEffATH() As String
LegPosEffATH = pLegPosEffATH
End Property
Public Property Let LegPosEffATH(Value As String)
pLegPosEffATH = Value
End Property
Bookmarks