All pastes #435647 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-04-12 01:28 UTC
rendered paste body
    Dim lviCurrentPort As New ListViewItem
    Dim dblTotalValue As Double = 0
    Dim strTicker, strPrice, strShares, strBasis, strValue, strTotalValue, strTickerList As String
    Dim dblPrice, dblshares, dblBasis, dblValue As Double
    Dim intStockCOunt, intListCount, intSelectedTicker 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 = 0 To Me.lstCurrentPort.SelectedIndices.Count - 1
            txtCurrentSelect.Text = lstCurrentPort.Items(intSelectedTicker).Text
        Next