Results 1 to 3 of 3

Private Variables: what are they good for (In VBA)? Non-technical/exp.-based guidance req.

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Private Variables: what are they good for (In VBA)? Non-technical/exp.-based guidance req.

    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
    Last edited by joe31623; 01-05-2016 at 06:31 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] How to access variables that are declared in private subroutine
    By Pan314 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-23-2015, 10:07 PM
  2. [SOLVED] Is a method or property better for manipulating several private variables and using inputs
    By joe31623 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2015, 01:54 PM
  3. Follow-up question about variables [Private]
    By xlBunny in forum Excel - New Users/Basics
    Replies: 10
    Last Post: 04-23-2015, 11:47 PM
  4. Good evening all, hope to find guidance
    By Rokn in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 10-01-2013, 08:35 PM
  5. Private modules and global variables
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-25-2005, 03:15 PM
  6. [SOLVED] Class Modules and Private Variables
    By Joe Cletcher in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2005, 03:20 PM
  7. [SOLVED] Declarations variables, Dim, some guidance please
    By Neal Zimm in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 08-17-2005, 04:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1