All of the controls you have added so
far are used to provide values to the functions that will calculate
an option price.
The way Visual Basic refers to a control
is by its Name. This means that all the Names for the controls you have
added MUST match the code we will be using.
It is very easy to misspell a Name,
or even add the wrong type of control, so in this step we will be testing
the Names and control types.
While looking at your form in Visual
Basic design mode, double-click on the dark blue title bar of the form.
This will open the "code behind" space for the form.
You should see some code already in
place, as in the following picture:
Put your cursor after "End Sub"
and press the Enter key. This will open up a blank line. Copy the code
below and Paste it into the blank line.
|
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
Dim int As Integer = Leg1Contracts.Value
Dim sng As Single = Leg1StockPrice.Value
sng = Leg1StrikePrice.Value
Dim dt As Date = Leg1EntryDate.Value
dt = Leg1ExpirationDate.Value
sng = Leg1OptionPrice.Value
sng = Leg1IV.Value
txt = Leg1Value.Text
sng = InterestRate.Value
sng = Dividends.Value
txt = Messages.Text
End Sub
|
This code does not actually do anything
except take advantage of some automatic error correcting abilites in
Visual Basic. Visual Basic will look at each of the Names and control
types in the code, and if it cannot find a control that matches the
Name, or the control is the wrong type, it will mark the code with a
blue squiggly line.
If you see any blue squiggly lines in
the code, check that the Name of the control in the Properties Window
in Design View matches the Name in the code.
After changing any misspelled Names
in the Property Window, the blue squiggly line should disappear in code
view.
If you still have some blue squiggly
lines, it could mean that the control is the wrong type. For instance,
you may have added a control as a TextBox, but it is supposed to be
a NumericUpDown.
If you find anything like that, select
the control in Design View and press the "delete" key to get rid of
it. Then add the correct type of control and set all its Properties,
as listed in the previous steps concerning control layout. Save your
project.