The Option-Graph Project Option-Graph.com

Basic Option Graph Step 8

Add the EquityShares Class

Similar to the way we added a Visual Basic Class for options in the Calculator Project, we will add a Class called EquityShares for dealing with the information we need to add and retrieve from the Stock Leg.

In the Solution Explorer at the top right corner of the Visual Basic screen, right-click on the name of the Project - "Basic Option Graph". On the menu that pops up, hover your mouse over Add, and then choose Class from the next window.

This will open a window to add a Class to the Project, with the name Class1.vb suggested at the bottom of the window. Change the name to EquityShares.vb, and click Add.

Visual Basic will open a window with the lines "Public Class EquityShares" and "End Class". Paste the following code to the blank line in between.

Dim ls As String
Dim nums As Integer
Dim entryp As Single
Dim include As Boolean
Public Sub New(ByVal longorshort As String, ByVal numshares As Integer, ByVal entryprice As Single, ByVal included As Boolean)
ls = longorshort
nums = numshares
entryp = entryprice
include = included
End Sub
Function totalvalue(ByVal displayprice As Decimal) As String
If include = True Then
Return FormatCurrency(valuesign() * displayprice * nums)
Else
Return FormatCurrency(0)
End If
End Function
Function colorize() As Color
If include = True Then
If ls = "Long" Then
Return Color.Pink
Else
Return Color.LightGreen
End If
Else
Return Color.Gray
End If
End Function
Function valuesign() As Integer
If ls = "Long" Then
Return 1
Else
Return -1
End If
End Function
Function pchart() As Single
If include = True Then
Return entryp
Else
Return 0
End If
End Function
Function vchart(ByVal sp As Single) As Single
If include = True Then
Return sp * valuesign() * nums
Else
Return 0
End If
End Function

Save your Project.

 

Home Page Downloads
Previous Step: Test the Names
Next Step: Add and Replace Code

Copyright 2017 option-info.com Privacy Policy

Questions, corrections, suggestions, comments to: this contact

Want to learn options, find strategies? Visit www.option-info.com