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