Hello
Today I am trying to put an error message showing that the client has no stock..I think I have to use the clientidlist to show if the client id does not show up in the clientidList than show error message stating the client has no stock..but I am not sure where to put it. Here is part of my code..

Public Class frmMain
    Dim clientLastNameList As New List(Of String)
    Dim clientFirstNameList As New List(Of String)
    Dim clientIDList As New List(Of Integer)  'list of all ids
    Dim clientPhoneList As New List(Of String) 'list of phone #s

    Dim tranFile As System.IO.StreamReader 'file of transaction data
    Dim tranFileName As String = "fatrans.txt"

 Private Sub btnSummary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSummary.Click
        Dim tid As String = ""
        Dim tcode As String = ""
        Dim tdate As Date
        Dim ttype As String = ""
        Dim tshares As Integer
        Dim tprice As Double
        Dim sname As String = ""
        Dim scode As String = ""
        Dim sprice As Double
        Dim total As Double
        Dim value As Double
        Dim ndx As Integer

        Dim clientStockCodeList As New List(Of String) 'list of codes in the client portfolio
        Dim clientShareList As New List(Of Integer) 'list of number of shares in the stock code

        'position the file at its beginning
        Call ResetTranFile()

        If Not IsNumeric(txtTargetID.Text) Or txtTargetID.Text = "" Then
            MessageBox.Show("No selected client")
            txtTargetID.Focus()
            txtTargetID.SelectAll()
            Exit Sub
        End If

        'print heading
        lblDisp.Text = "code".PadRight(9) & "Name".PadRight(23) & "shares".PadRight(10) & "price".PadRight(11) & "value" & vbCrLf

        Do While tranFile.Peek <> -1 ' if the next tran exist
            Call GetNextTran(tid, tcode, tdate, ttype, tshares, tprice)

            If tid = txtTargetID.Text Then

                ' If tcode is not already in the list of the client’s stock codes
                If Not clientStockCodeList.Contains(tcode) Then

                    ' Add tcode to the end of the client’s list of stock codes
                    ' Add tshares to the end of the client’s list of stock 
                    clientStockCodeList.Add(tcode)
                    clientShareList.Add(tshares)
                Else
                    'Find the index position of tcode in the list of client stock codes
                    ndx = clientStockCodeList.IndexOf(tcode)

                    'For ndx = 0 To clientShareList.Count - 1
                    If ttype = "B" Then
                        ' increase the stock shares in the same index position in the shares
                        ' list by tshares
                        clientShareList.Item(ndx) += tshares
                        'MessageBox.Show(CStr(clientShareList.Item(ndx)))
                    ElseIf ttype = "S" Then
                        'decrease the stock shares in the same index position in the shares
                        ' list by tshares
                        clientShareList.Item(ndx) -= tshares
                        ' MessageBox.Show(CStr(clientShareList.Item(ndx)))
                    End If
                    ' Next
                End If
            End If
        Loop

        For Each code As String In clientStockCodeList
            If tshares > 0 Then
                Call GetStockData(code, sname, sprice) 'used to get the name of stock

                'gets the index of the code in the clientStockcodelist
                ndx = clientStockCodeList.IndexOf(code)

                'calls the index in the parrallel list
                value = sprice * clientShareList.Item(ndx) 'number of shares of this stock (in parallel list of client shares)

                'if total shares not equal to 0 display label
                If clientShareList.Item(ndx) <> 0 Then
                    lblDisp.Text += code.PadRight(9) & sname.PadRight(23) & clientShareList.Item(ndx).ToString.PadRight(10) & _
                              FormatCurrency(sprice).PadRight(11) & FormatCurrency(value) & vbCrLf
                End If
            End If

            total += value ' Add value for this stock holding to client total
        Next

        'not sure how to write the error message if the client has no stock
        If clientIDList.(txtTargetID.Text) Then
            lblDisp.Text = "client has no stock"
        End If

        lblDisp.Text += "Total portfolio value as of " & Today.ToShortDateString & "  =  " & FormatCurrency(total).ToString
    End Sub

thank you really appreciate any help

Recommended Answers

All 4 Replies

easy:

For i As Integer = 0 to clientIDList.Count-1
'CInt converts string to integer but raises error if
'a value isn't a number so watch out what you write into 
'txtTargetID.Text!
   If clientIDList(i) = CInt(txtTargetID.Text) Then
      'ID found write needed code here
   ElseIf i = clientIDList.Count-1 Then
      'No match in clientIDList... Raise MsgBox
      MsgBox("ID not found!", vbOKOnly, "Error")
   End If
Next

or you could try:

If Not clientIDList.Contains(CInt(txtTargetID.Text)) Then
   'Raise MsgBox
   MsgBox("ID not found!", vbOKOnly, "Error")
End If

Thank you I used this instead and it worked, same idea

If clientStockCodeList.Count = 0 Then
            lblDisp.Text = "client has no stock"
            txtTargetID.Focus()
            txtTargetID.SelectAll()
            Exit Sub
        End If

I have another input validation that im stuck in..
I have to validate if the client id (tid) has stock for that year (tdate.year)whenever they click on the YTD button..
Here is where it belongs..I'm not sure where or how..have ideas but they don't work..

Private Sub btnGainLoss_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYTD.Click

        Dim sname As String = ""
        Dim sprice As double
        Dim tid As String = txtTargetID.Text
        Dim tcode As String = ""
        Dim tdate As Date
        Dim ttype As String = ""
        Dim tshares As Integer
        Dim tprice As Double

        'position the file at its beginning
        Call ResetTranFile()

        If Not IsNumeric(txtTargetID.Text) Or txtTargetID.Text = "" Then
            MessageBox.Show("no client selected")
            txtTargetID.Focus()
            txtTargetID.SelectAll()
            Exit Sub
        End If

        If txtClientName.Text = "" Then
            MessageBox.Show("No client selected")
            Exit Sub
        End If

        If CDbl(txtYear.Text) > Today.Year Or CDbl(txtYear.Text) <= Today.Year - 100 Then
            MessageBox.Show("Enter a valid year")
            txtYear.Focus()
            txtYear.SelectAll()
            Exit Sub
        End If

        'print label headings
        lblDisp.Text = "Date".PadRight(12) & "Name".PadRight(20) & "Type".PadRight(7) & _
        "Shares".PadRight(9) & "Price" & vbCrLf

        'display transactions from target year for current client
        Do While tranFile.Peek <> -1
            Call GetNextTran(tid, tcode, tdate, ttype, tshares, tprice)
            If txtTargetID.Text = tid And CDbl(txtYear.Text) = tdate.Year Then
                Call GetStockData(tcode, sname, sprice)

                lblDisp.Text += tdate.ToShortDateString.PadRight(11) & sname.PadRight(22) & ttype.PadRight(6) & _
                tshares.ToString.PadRight(9) & FormatCurrency(tprice) & vbCrLf
            End If
        Loop

        'this doesn't work..not sure how to write this validateion
        If tdate.Year = 0 Then
            lblDisp.Text = "no transaction in target year"
            txtTargetID.Focus()
            txtTargetID.SelectAll()
            Exit Sub
        End If
    End Sub

thank you

Thank you I used this instead and it worked, same idea

If clientStockCodeList.Count = 0 Then
            lblDisp.Text = "client has no stock"
            txtTargetID.Focus()
            txtTargetID.SelectAll()
            Exit Sub
        End If

I have another input validation that im stuck in..
I have to validate if the client id (tid) has stock for that year (tdate.year)whenever they click on the YTD button..
Here is where it belongs..I'm not sure where or how..have ideas but they don't work..

Private Sub btnGainLoss_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYTD.Click

        Dim sname As String = ""
        Dim sprice As double
        Dim tid As String = txtTargetID.Text
        Dim tcode As String = ""
        Dim tdate As Date
        Dim ttype As String = ""
        Dim tshares As Integer
        Dim tprice As Double

        'position the file at its beginning
        Call ResetTranFile()

        If Not IsNumeric(txtTargetID.Text) Or txtTargetID.Text = "" Then
            MessageBox.Show("no client selected")
            txtTargetID.Focus()
            txtTargetID.SelectAll()
            Exit Sub
        End If

        If txtClientName.Text = "" Then
            MessageBox.Show("No client selected")
            Exit Sub
        End If

        If CDbl(txtYear.Text) > Today.Year Or CDbl(txtYear.Text) <= Today.Year - 100 Then
            MessageBox.Show("Enter a valid year")
            txtYear.Focus()
            txtYear.SelectAll()
            Exit Sub
        End If

        'print label headings
        lblDisp.Text = "Date".PadRight(12) & "Name".PadRight(20) & "Type".PadRight(7) & _
        "Shares".PadRight(9) & "Price" & vbCrLf

        'display transactions from target year for current client
        Do While tranFile.Peek <> -1
            Call GetNextTran(tid, tcode, tdate, ttype, tshares, tprice)
            If txtTargetID.Text = tid And CDbl(txtYear.Text) = tdate.Year Then
                Call GetStockData(tcode, sname, sprice)

                lblDisp.Text += tdate.ToShortDateString.PadRight(11) & sname.PadRight(22) & ttype.PadRight(6) & _
                tshares.ToString.PadRight(9) & FormatCurrency(tprice) & vbCrLf
            End If
        Loop

        'this doesn't work..not sure how to write this validateion
        If tdate.Year = 0 Then
            lblDisp.Text = "no transaction in target year"
            txtTargetID.Focus()
            txtTargetID.SelectAll()
            Exit Sub
        End If
    End Sub

thank you

1. This is another problem... You should've marked this one as solved and opened a new thread
2. I'm assuming that you get the "tdate" for current "tid" with "GetNextTran" or "GetStockData"
If 2. is true then you probably should put the validation code into that sub/function I think. Since you didn't post the relevant code I can't tell for sure...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.