VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = "ContDivStock" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Option Explicit Implements Stock Private mInitPrice As Currency Private mCurrPrice As Currency Private mDivRate As Single Private mPu As Single Private mUpPercent As Single Private mDownPercent As Single Private mName As String Private Sub Stock_advance(ByVal days As Integer) Dim i As Integer For i = 1 To days If Rnd < mPu Then mCurrPrice = mCurrPrice * (1 + mUpPercent) Else mCurrPrice = mCurrPrice * (1 - mDownPercent) End If If mCurrPrice < 0 Then MsgBox "bankrupt!" Next i End Sub Public Sub advance(ByVal days As Integer) Stock_advance days End Sub Private Property Get Stock_currPrice() As Currency Stock_currPrice = mCurrPrice End Property Public Property Get currPrice() As Currency currPrice = Stock_currPrice End Property Private Property Let Stock_downPercent(ByVal sPercent As Single) If sPercent > 1 Or sPercent < 0 Then Err.Raise 5 'Invalid argument Exit Property End If mDownPercent = sPercent End Property Public Property Let downPercent(ByVal sPercent As Single) Stock_downPercent = sPercent End Property Private Property Get Stock_downPercent() As Single Stock_downPercent = mDownPercent End Property Public Property Get downPercent() As Single downPercent = Stock_downPercent End Property Private Property Let initPrice(ByVal cPrice As Currency) If cPrice <= 0 Then Err.Raise 5 'Invalid argument Exit Property End If mInitPrice = cPrice End Property Private Property Get Stock_initPrice() As Currency Stock_initPrice = mInitPrice End Property Public Property Get initPrice() As Currency initPrice = Stock_initPrice End Property Private Function Stock_percentGain() As Single Stock_percentGain = (mCurrPrice - mInitPrice) / mInitPrice End Function Public Function percentGain() As Single percentGain = Stock_percentGain End Function Private Property Get Stock_pu() As Single Stock_pu = mPu End Property Public Property Get pu() As Single pu = Stock_pu End Property Private Property Let Stock_pu(ByVal sProb As Single) If sProb >= 1 Or sProb < 0 Then Err.Raise 5 'Invalid argument Exit Property End If mPu = sProb End Property Public Property Let pu(ByVal sProb As Single) Stock_pu = sProb End Property Private Property Let Stock_stockName(ByVal strName As String) If strName = "" Then Err.Raise 5 'Invalid argument Exit Property End If mName = strName End Property Public Property Let stockName(ByVal strName As String) Stock_stockName = strName End Property Private Property Get Stock_stockName() As String Stock_stockName = mName End Property Public Property Get stockName() As String stockName = Stock_stockName End Property Private Property Let Stock_upPercent(ByVal sPercent As Single) If sPercent < 0 Then Err.Raise 5 'Invalid argument Exit Property End If mUpPercent = sPercent End Property Public Property Let upPercent(ByVal sPercent As Single) Stock_upPercent = sPercent End Property Private Property Get Stock_upPercent() As Single Stock_upPercent = mUpPercent End Property Public Property Get upPercent() As Single upPercent = Stock_upPercent End Property Public Property Get divRate() As Single divRate = mDivRate End Property Public Property Let divRate(ByVal sRate As Single) If sRate >= 1 Or sRate < 0 Then Err.Raise 5 'Invalid argument Exit Property End If mDivRate = sRate End Property Public Sub payDividend() mCurrPrice = mCurrPrice * (1 - mDivRate) End Sub Public Sub initialize(ByVal strName As String, ByVal cPrice As Currency, ByVal sPu As Single, ByVal sUpPercent As Single, ByVal sDownPercent As Single, ByVal sDivRate As Single) stockName = strName initPrice = cPrice mCurrPrice = mInitPrice pu = sPu upPercent = sUpPercent downPercent = sDownPercent divRate = sDivRate End Sub