This has worked forever. Yesterday, it quit. It is probably simple, but I'm not seeing it. The routine is calculating but net returning the answer.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Function GetPerGain(booClosed As Boolean, dblLossGain As Double, _
dblBoughtCst As Double, dblCostBasis As Double, dblDiv As Double) As Double
'Verify you are passing the in the correct values
'Add some debug.print here to see if all paramaters are being passed in correctly
Debug.Print "Boo " & booClosed & " LossGain " & dblLossGain & " BoughtCst " & dblBoughtCst & " cost basis " & dblCostBasis & " Div " & dblDiv
If booClosed = -1 Then
Debug.Print "BooClosed = True"
GetPerGain = [dblLossGain] / [dblBoughtCst]
Else
Debug.Print "BooClosed = false"
If dblCostBasis = 0 Then
GetPerGain = 0
ElseIf dblCostBasis >= dblDiv Then
GetPerGain = dblLossGain / (dblCostBasis - dblDiv)
Else
GetPerGain = dblLossGain / (dblCostBasis + dblDiv)
End If
End If
End Function
Public Sub TestGetPerGain()
Debug.Print " GetPerGain " & GetPerGain(True, 100, 50, 25, 0)
Debug.Print " GetPerGain " & GetPerGain(False, 100, 50, 25, 20)
Debug.Print " GetPerGain " & GetPerGain(False, 100, 50, 25, 30)
End Sub
Dim dblMyNumber As Double
...
dblMyNumber = GetPerGain(True, 100, 50, 25, 0)
MsgBox "My number is " & dblMyNumber
...