3 Replies - 807 Views - Last Post: 07 April 2011 - 08:45 PM Rate Topic: -----

#1 Msqueen082   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 06-February 11

working with lists

Posted 06 April 2011 - 04:33 PM

I would really appreciate some help in a project I am working on..I am almost done with it but need to put a message somewhere before the last part of the label gets read in that saids, "No stock found for this client in the list"..Not sure how to write this input message..could sure use some help..here is 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

        'dont understand why this is not working...
        If tranFileName.Contains(txtTargetID.Text) Then
            lblDisp.Text = "client has no stock"
        End If

        '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

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

       
    End Sub


thank you
:angel:

Is This A Good Question/Topic? 0
  • +

Replies To: working with lists

#2 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: working with lists

Posted 06 April 2011 - 07:48 PM

I think instead of loading several Lists and reference the same element by index. Maybe, a custom class. Then a List(Of <this custom class>) now we can use simple iteration to find the data or LINQ the data out. I think you find this would flow better. The other advantage is storing this list with serialization maybe be of benefit.
Was This Post Helpful? 1
  • +
  • -

#3 Msqueen082   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 06-February 11

Re: working with lists

Posted 06 April 2011 - 09:03 PM

Thank you for your quick response but the code as is works fine...It does what it's suppose to..I just need to add a the message..don't know where to place it in the code so that it reads "if the client id is not found in the transfileName than "client has no stock".
something like this
If tranFileName.Contains(txtTargetID.Text) Then
            lblDisp.Text = "client has no stock"
            txtTargetID.Focus()
            txtTargetID.SelectAll()
            Exit Sub
        End If


I don't know where in the code to put this where it search the file than as soon as it finds that it doesnot contain whatever id is typed in a textbox than "client has no stock"
:angel:
Was This Post Helpful? 0
  • +
  • -

#4 Msqueen082   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 06-February 11

Re: working with lists

Posted 07 April 2011 - 08:45 PM

solved this problem..took me a while but I did it..thank you for your help hawkvalley1..here is what I used instead
If clientStockCodeList.Count = 0 Then
            lblDisp.Text = "client has no stock"
            txtTargetID.Focus()
            txtTargetID.SelectAll()
            Exit Sub
        End If


worked great..thanks again
:angel:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1