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