hello
I wrote this code using classes and it keeps giving me the error message :
a nullreference exception was unhandeled/Object reference not set to an instance of an object.
I am trying to add stock code and stock shares to the list of transactions using a currClient As Client (which, holds the current clients information) that I have listed as a global. I also have a method called getClientTransaction in the client class.(3 classes stock, transaction, and client). Whenever the click on the summary button it should give me all client summary, but it keeps crashing...Did some research on the error, and nothing helped...Could sure use some help getting unstuck...
here is part of my code
Private Sub btnGainLoss_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYTD.Click
'display transactions from current year for current client
Dim tyear As Integer
Dim ndx As Integer
If txtClientName.Text = "" Then
MessageBox.Show("no client selected")
Exit Sub
End If
If Not Integer.TryParse(txtYear.Text, tyear) Then
MessageBox.Show("enter a valid year")
txtYear.Focus()
txtYear.SelectAll()
Exit Sub
Else
If tyear < Today.Year - 100 Or tyear > Today.Year Then
MessageBox.Show("enter a valid year")
txtYear.Focus()
txtYear.SelectAll()
Exit Sub
End If
End If
If currClient.clientCount = 0 Then
lblDisp.Text = "No transactions in target year"
Else
lblDisp.Text = "Date Stock Type Share Price proceeds" & vbCrLf
For ndx = 0 To currClient.clientCount - 1
If currClient.getClientTransaction(ndx).TranDate.Year = CDbl(txtYear.Text) Then
stock1 = New stock(currClient.getClientTransaction(ndx).TranStockCode)
lblDisp.Text += currClient.getClientTransaction(ndx).TranDate.ToShortDateString.PadRight(12) & _
stock1.StockName.PadRight(3) & currClient.getClientTransaction(ndx).TranType.PadRight(7) & _
currClient.getClientTransaction(ndx).TranShares.ToString.PadRight(9) & FormatCurrency(currClient.getClientTransaction(ndx).TranSharePrice) & " " & _
FormatCurrency(currClient.getClientTransaction(ndx).t_Shares) & vbCrLf
End If
Next
End If
End Sub
Thank you