Hi
I could sure use some help. In a form of a push in the right direction. I am tryig to remove all multiple tcode (stock name) and add (if tcode is "B" add the shares and if tcode is "S" subtract the shares) them together in just one line of text in a label and if the shares add up to 0 after subtracting the shares bought and sold than don't add it to the the label.

The following are my total trasactions for id# 111
tid , tcode , ttype , tshares , tprice
111 frd B 500 $300.00
111 frd S 100 $320.00 (500- 100 = 400)
111 frd S 100 $250.00 (400 - 100 = 300)

When I hit the summary button it should display
tid , tcode , tshares , tprice
111 frd 300 $275.00

I know I am only working with total shares(tshares), Im not sure how to put it so it will read only one line of the frd stock. I think I have to subtract each stock as it goes in a loop but I am not sure how to apply it to my code. I already used a loop to read each line, I think I need a for loop somewhere. I tried puting it in different locations but it will not work..here my code.

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
       
        'position the file at its beginning
        Call ResetTranFile()

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

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

        Do While tranFile.Peek <> -1

            Call GetNextTran(tid, tcode, tdate, ttype, tshares, tprice)

            If tid = (txtTargetID.Text) Then

                Call GetStockData(tcode, sname, sprice)

                'not sure if this for loop is correct
                For ndx = 0 To tcode.Count - 1
                    If ttype = "B" Then
                        tshares += tshares
                    ElseIf ttype = "S" Then
                        tshares -= tshares
                    End If
                Next
                total = tshares * tprice

                lblDisp.Text += tcode.PadRight(9) & sname.PadRight(23) & tshares.ToString.PadRight(10) & _
                           FormatCurrency(sprice).PadRight(11) & FormatCurrency(total) & vbCrLf
            End If
        Loop
        lblDisp.Text += "Total portfolio value as of " & tdate.ToShortDateString & "  =  " & FormatCurrency(total).ToString
    End Sub

could really appreciate some help..
thank you much

Recommended Answers

All 10 Replies

I changed it a bit but still not getting correct data

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 nextTShares As Integer

        'position the file at its beginning
        Call ResetTranFile()

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

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

        If clientIDList.Contains(CInt(txtTargetID.Text)) Then
            Call GetNextTran(tid, tcode, tdate, ttype, tshares, tprice)

            For ndx = 0 To clientIDList.Count - 1
                If clientIDList.Item(ndx) = CDbl(txtTargetID.Text) Then
                    If ttype = "B" Then
                        nextTShares += tshares
                        nextTShares += 1
                    ElseIf ttype = "S" Then
                        nextTShares -= tshares
                    End If

                    total = tshares * tprice

                    Call GetStockData(tcode, sname, sprice) 'used to get the name of stock

                    lblDisp.Text += tcode.PadRight(9) & sname.PadRight(23) & tshares.ToString.PadRight(10) & _
                                                FormatCurrency(sprice).PadRight(11) & FormatCurrency(total) & vbCrLf
                End If
            Next

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

not sure if i completely follow your concept but this jumps out in your for loop so try this

For ndx = 0 To tcode.Count - 1
                    If ttype = "B" Then
                        tshares = tshares+ tshares
                    ElseIf ttype = "S" Then
                        tshares = tshares - tshares
                    End If
                Next

hope this helps

acctually if you are incrementing these values it should be

For ndx = 0 To tcode.Count - 1
                    If ttype = "B" Then
                        tshares = tshares+ 1
                    ElseIf ttype = "S" Then
                        tshares = tshares - 1
                    End If
                Next

Thank you for your response...helped somewhat

What I am trying to do is take all the records in a file and read each line. After reading each line I add all the stock that have the same tcode together in a label.
Like for example these are the records that appear in the tranfile
111 FRD 09/23/2001 B 500 300.00
111 ENRON 09/30/2001 B 100 50.00
111 ENRON 10/27/2002 B 100 60.00
111 DRYMF 01/17/2002 B 200 10.00
111 ENRON 04/25/2003 B 200 70.00
111 FRD 06/13/2003 S 100 320.00
111 ENRON 10/10/2004 S 100 80.00
111 CAYBC 12/17/2004 B 50 120.00
555 DRYMF 01/14/2005 B 200 12.00
111 DRYMF 01/25/2006 S 100 14.00
111 ENRON 06/06/2007 S 100 1.00
222 GLOM 11/24/2008 B 200 30.00
222 IBM 11/24/2008 B 100 420.00
222 BAHHF 04/14/2009 B 100 40.00
222 GLOM 08/11/2009 S 200 35.00
222 IBM 08/11/2009 B 50 410.00
222 BAHHF 09/27/2009 B 100 44.00
333 FRD 10/11/2009 B 200 280.00
111 CAYBC 01/24/2010 S 50 125.00
111 FRD 02/25/2010 S 100 250.00
333 FRD 03/04/2010 S 100 250.00
555 DRYMF 03/09/2010 S 100 18.00
555 DRYMF 03/19/2010 S 100 20.00
333 FRD 04/06/2010 B 50 220.00
333 FRD 05/01/2010 S 140 200.00
222 BAHHF 07/08/2010 S 200 48.00
222 IBM 07/08/2010 S 50 425.00

These are all the tid, tcode, tdate, ttype, tshares, tprice used in a fuction.
After reading each line and minusing "S" and adding "B" for let say client 111 i come up with the folling items in the label

tid , tcode , tshares , tprice
111 frd 300 $275.00

sorry about that it should read

Code------Name-----------------Shares---Price--------Value
frd-------ford motor corp--------300----$275.00----$82,500.00
ENRON-----ENRON ENERGY-----------200-----$0.45---------$90.00
DRYMF-----DREYFUSS MUTUAL FUND---100-----$25.20------2,520.00

Total portfolio value as of 3/31/2011 = $85,110.00

right ok think i understand what you are trying to do so try this

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 nextTShares As Double
 
        'position the file at its beginning
        Call ResetTranFile()
 
        If Not IsNumeric(txtTargetID.Text) Or txtTargetID.Text = "" Then
            MessageBox.Show("No selected client")
            Exit Sub
        End If
 
        lblDisp.Text = "code".PadRight(9) & "Name".PadRight(23) & "shares".PadRight(10) & "price".PadRight(11) & "value" & vbCrLf
 
        If clientIDList.Contains(CInt(txtTargetID.Text)) Then
            Call GetNextTran(tid, tcode, tdate, ttype, tshares, tprice)
 
            For ndx = 0 To clientIDList.Count - 1
                If clientIDList.Item(ndx) = CDbl(txtTargetID.Text) Then
                    If ttype = "B" Then
                        nextTShares =nextTshares + tshares
                        
                    ElseIf ttype = "S" Then
                        nextTShares  = nextTshares - tshares
                    End If
 
                    total = nexTtshares * tprice
 
                    Call GetStockData(tcode, sname, sprice) 'used to get the name of stock
 
                    lblDisp.Text = tcode.PadRight(9) & sname.PadRight(23) & tshares.ToString.PadRight(10) & _
                                                FormatCurrency(sprice).PadRight(11) & FormatCurrency(total) & vbCrLf
                End If
            Next
 
            lblDisp.Text = "Total portfolio value as of " & tdate.ToShortDateString & "  =  " & FormatCurrency(total).ToString
        End If
    End Sub

think if i have understood you this time this should work

Thank you, really appreciate your help... it worked....Hurray!!!

no probs just mark the thread as solved :)

commented: Nice job helping this guy out. :) +1

how do i do that ?

should be at the bottom of the thread

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.