Dim lviCurrentPort As New ListViewItem
Dim dblTotalValue As Double = 0
Dim strTicker, strPrice, strShares, strBasis, strValue, strTotalValue, strTickerList, strSelectionTicker, strNewTicker, strNewShares, strEditBasis, strEditShares As String
Dim strNewBasis, strNewPrice, strEditTicker, strEditPrice, strEditValue, strEditTotalValue, strUpdateValue, strUpdateTotalValue, strUpdatePrice, strUpdateShares As String
Dim strUpdateBasis As String
Dim dblPrice, dblshares, dblBasis, dblValue, dblEditPrice, dblEditShares, dblEditBasis, dblEditValue, dblNewBasis, dblEditTotalValue As Double
Dim dblUpdatePrice, dblUpdateShares, dblUpdateValue, dblUpdateTotalValue, dblUpdateBasis As Double
Dim intStockCOunt, intListCount, intSelectedTicker, intSelectedTickers, intIndex, intDelete, intUpdate, intGetData, intABort As Integer
Dim exactMatch As Boolean
Dim intRow As Integer = 0
' If the user leaves one of the fields blank, it will produce an error and give focus to that specific
' field.
Private Sub btnAddStock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddStock.Click
If txtTicker.Text = "" Then
MessageBox.Show("Oops.. you left Ticker blank", "Ticker Blank")
txtTicker.Focus()
ElseIf txtShares.Text = "" Then
MessageBox.Show("Oops..you left Shares blank", "Shares Blank")
txtShares.Focus()
ElseIf txtPrice.Text = "" Then
MessageBox.Show("Oops..you left Price blank", "Price Blank")
txtPrice.Focus()
End If
'Line 510 ensures that the three fields are not blank.
Do While txtTicker.Text.ToString <> "" And txtShares.Text.ToString <> "" And txtPrice.Text.ToString <> ""
' Converts the number entered in the Price field to a double data type.
dblPrice = Convert.ToDouble(txtPrice.Text)
' Converts the number entered in the Shares field to a double data type.
dblshares = Convert.ToDouble(txtShares.Text)
' Creates a variable by multiplying Price * Shares
dblBasis = dblPrice * dblshares
' Creates a variable by multiplying Price & Shares
dblValue = dblPrice * dblshares
' Creates a variable by adding Total Value & Value
dblTotalValue = dblTotalValue + dblValue
' Converts the Basis field to a string
strBasis = Convert.ToString(dblBasis)
' Converts the Value field to a string
strValue = Convert.ToString(dblValue)
' Converts the Total Value field to a string
strTotalValue = Convert.ToString(dblTotalValue)
' Creates a new list view item called lviCurrentPort with the first item
' being the Ticker field.
lviCurrentPort = New ListViewItem(txtTicker.Text)
' Adds the Basis subitem and converts it to a Currency.
lviCurrentPort.SubItems.Add(Format$(strBasis, "Currency"))
' Adds the Shares sub item.
lviCurrentPort.SubItems.Add(txtShares.Text)
' Adds the Price sub item and converts it to a Currency.
lviCurrentPort.SubItems.Add(Format$(txtPrice.Text, "Currency"))
' Adds the Value sub item and converts it to a Currency.
lviCurrentPort.SubItems.Add(Format$(strValue, "Currency"))
' Loop that check each item in the list view box.
intListCount = Convert.ToInt32(lstCurrentPort.Items.Count)
For intRow = 0 To intListCount - 1
' If the text in the Ticker field matches any Item in the list view box, an error
' message will display and focus will be given to the Ticker field.
strTicker = Convert.ToString(txtTicker.Text)
strTickerList = Convert.ToString(lstCurrentPort.Items(intRow).Text)
If strTicker = strTickerList Then
exactMatch = True
Else
exactMatch = False
End If
Next
If exactMatch = True Then
MessageBox.Show("Duplicate Detected")
txtTicker.Text = ""
txtTicker.Focus()
End If
If exactMatch = False Then
' Takes the listviewitem created with all the items & subitems and adds it to the
' List View Box called lstCurrentPort
lstCurrentPort.Items.Add(lviCurrentPort)
' Once a duplicate is not found, these lines of code will run.
txtTotalValue.Text = Format$(strTotalValue, "Currency")
txtTicker.Text = ""
txtShares.Text = ""
txtPrice.Text = ""
' If the lines of code is greater than 10, an error message will display.
If lstCurrentPort.Items.Count > 10 Then
MessageBox.Show("Trial Version only allows 10 entries")
End If
End If
Loop
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub lstCurrentPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstCurrentPort.SelectedIndexChanged
For intSelectedTicker = 1 To lstCurrentPort.SelectedIndices.Count
strSelectionTicker = intSelectedTicker.ToString
txtCurrentSelect.Text = strSelectionTicker
Next
End Sub
Private Sub btnGetData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetData.Click
For intGetData = 0 To lstCurrentPort.SelectedItems.Count - 1
If lstCurrentPort.SelectedIndices.Count >= 1 Then
txtNewTicker.Text = lstCurrentPort.Items(intGetData).SubItems(0).Text
txtNewBasis.Text = lstCurrentPort.Items(intGetData).SubItems(1).Text
txtNewShares.Text = lstCurrentPort.Items(intGetData).SubItems(2).Text
txtNewPrice.Text = lstCurrentPort.Items(intGetData).SubItems(3).Text
Else
MessageBox.Show("Please select a ticker to get silly!", "No Ticker Selected")
End If
Next
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
For intUpdate = 0 To lstCurrentPort.SelectedIndices.Count - 1
If lstCurrentPort.SelectedIndices.Count >= 1 Then
dblUpdateShares = Convert.ToDouble(strEditShares)
dblUpdatePrice = Convert.ToDouble(strEditPrice)
dblUpdateBasis = dblUpdatePrice * dblUpdateShares
dblUpdateValue = dblUpdatePrice * dblUpdateShares
dblUpdateTotalValue = dblUpdateValue + dblTotalValue
strUpdateShares = Convert.ToString(dblUpdateShares)
strUpdatePrice = Convert.ToString(dblUpdatePrice)
strUpdateBasis = Convert.ToString(dblUPdateBasis)
strUpdateValue = Convert.ToString(dblUpdateValue)
strUpdateTotalValue = Convert.ToString(dblUpdateTotalValue)
lstCurrentPort.Items(intUpdate).SubItems(0).Text = strEditTicker.ToString
lstCurrentPort.Items(intUpdate).SubItems(1).Text = strUpdateBasis
lstCurrentPort.Items(intUpdate).SubItems(2).Text = strUpdateShares
lstCurrentPort.Items(intUpdate).SubItems(3).Text = strUpdatePrice
lstCurrentPort.Items(intUpdate).SubItems(4).Text = strUpdateValue
txtNewTicker.Text = ""
txtNewBasis.Text = ""
txtNewShares.Text = ""
txtNewPrice.Text = ""
Else
MessageBox.Show("Please select a ticker to update silly!", "No Ticker Selected")
End If
Next
End Sub
Private Sub txtNewTicker_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNewTicker.TextChanged
strEditTicker = txtNewTicker.Text
End Sub
Private Sub txtNewBasis_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNewBasis.TextChanged
strEditBasis = txtNewBasis.Text
End Sub
Private Sub txtNewShares_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNewShares.TextChanged
strEditShares = txtNewShares.Text
End Sub
Private Sub txtNewPrice_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNewPrice.TextChanged
strEditPrice = txtNewPrice.Text
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
For intDelete = 0 To lstCurrentPort.SelectedIndices.Count - 1
lstCurrentPort.Items.RemoveAt(lstCurrentPort.SelectedIndices(intDelete))
txtNewTicker.Text = ""
txtNewBasis.Text = ""
txtNewShares.Text = ""
txtNewPrice.Text = ""
Next
End Sub
Private Sub btnAbort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbort.Click
lstCurrentPort.Items.Clear()
txtNewTicker.Text = ""
txtNewBasis.Text = ""
txtNewShares.Text = ""
txtNewPrice.Text = ""
txtTicker.Focus()
End Sub