The Option-Graph Project Option-Graph.com

Basic Option Graph Step 7

Test the Names

As we did for the Option Calculator Project, we are going to give some code that checks the Name of each Control you added. Names are important because that is how Visual Basic refers to the Controls in code. If the Name of a Control is missing or misspelled you will get an error message when trying to use the program.

First, click on the tab that says "Form1.vb" to open the "code behind" area of Form1. We are going to do a major rewrite of all the functions because of adding the additional option legs, stock leg, check date IV, and total field. We will give that code later in the project. For right now, we are going to get rid of everything we already have.

Select everything between (but not including) the first line ("Public Class Form1") and the last line ("End Class"), and delete it.

Now copy and paste the following code to a blank line between "Public Class Form1" and "End Class".

As before, if Visual Basic marks anything with a squiggly blue line, it probably means the Name Property of that Control is misspelled or not changed to the new name. Use the Properties window to change the Name to match what is in the code.

Sub TestNames()

'this sub does not actually do anything, it just tests that you have the correct names for the various controls
'if you see a name such as "Leg1Type" underlined with a blue squiggly line below, it probably means you misspelled the name of the control
'change the name of the control in the Properties window to match what is shown below
'do not change the names below - they are the correct names, which MUST be used in order for all functions to work

'a blue squiggly line can also indicate that you added the wrong type of control
'for instance, Leg1Contracts is supposed to be a NumericUpDown control
'if you added it as a TextBox instead, there will be a blue squiggly line under all of "Leg1Contracts.Value", not just the name

Dim txt As String = Leg1Type.Text
txt = Leg2Type.Text
txt = Leg3Type.Text
txt = Leg4Type.Text
txt = StockLegType.Text
Dim int As Integer = Leg1Contracts.Value
int = Leg2Contracts.Value
int = Leg3Contracts.Value
int = Leg4Contracts.Value
int = StockLegShares.Value
Dim sng As Single = Leg1StockPrice.Value
sng = Leg2StockPrice.Value
sng = Leg3StockPrice.Value
sng = Leg4StockPrice.Value
sng = StockLegStockPrice.Value
sng = Leg1StrikePrice.Value
sng = Leg2StrikePrice.Value
sng = Leg3StrikePrice.Value
sng = Leg4StrikePrice.Value
Dim dt As Date = Leg1EntryDate.Value
dt = Leg2EntryDate.Value
dt = Leg3EntryDate.Value
dt = Leg4EntryDate.Value
dt = Leg1ExpirationDate.Value
dt = Leg2ExpirationDate.Value
dt = Leg3ExpirationDate.Value
dt = Leg4ExpirationDate.Value
sng = Leg1OptionPrice.Value
sng = Leg2OptionPrice.Value
sng = Leg3OptionPrice.Value
sng = Leg4OptionPrice.Value
sng = Leg1IV.Value
sng = Leg2IV.Value
sng = Leg3IV.Value
sng = Leg4IV.Value
txt = Leg1Value.Text
txt = Leg2Value.Text
txt = Leg3Value.Text
txt = Leg4Value.Text
txt = StockLegValue.Text
sng = Leg1CheckIV.Value
sng = Leg2CheckIV.Value
sng = Leg3CheckIV.Value
sng = Leg4CheckIV.Value
sng = InterestRate.Value
sng = Dividends.Value
txt = Messages.Text
Dim bl As Boolean = Leg1Include.Checked
bl = Leg2Include.Checked
bl = Leg3Include.Checked
bl = Leg4Include.Checked
bl = StockLegInclude.Checked
txt = EntryValue.Text
txt = Leg1ExpNext.Name
txt = Leg2ExpNext.Name
txt = Leg3ExpNext.Name
txt = Leg4ExpNext.Name
txt = Leg1ExpPrev.Name
txt = Leg2ExpPrev.Name
txt = Leg3ExpPrev.Name
txt = Leg4ExpPrev.Name
txt = B_FindIV.Text
txt = B_FindPrice.Text
txt = B_CopyLeg1.Text
End Sub

 

 

Home Page Downloads
Previous Step: Add the Chart Control
Next Step: Add the EquityShares Class

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