943,691 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 7807
  • VB.NET RSS
Nov 9th, 2008
0

Null Reference Exception Unhandled

Expand Post »
I am getting the above error from the following code and I a not understanding why.

VB.NET Syntax (Toggle Plain Text)
  1. fileWriter.WriteLine( _
  2. record.strFirstName & "," & record.strLastName & "," & _
  3. record.strStudentId & "," & record.strCourseName & "," & _
  4. record.strGrade)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
robee31 is offline Offline
2 posts
since Nov 2008
Nov 11th, 2008
0

Re: Null Reference Exception Unhandled

hi
send ur ful code then v can help u
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008
Nov 11th, 2008
0

Re: Null Reference Exception Unhandled

Here is the entire code, I figured out why I am getting the above error yet I am not able to get the code to write to the file that is created.

Quote ...
VB.NET Syntax (Toggle Plain Text)
  1. Private Sub btnEnter_Click(ByVal sender As System.Object, _
  2. ByVal e As System.EventArgs) _
  3. Handles btnEnter.Click
  4.  
  5. Dim values As String() = GetTextBoxValues()
  6.  
  7. Dim record As New GradeBookDataCollector()
  8.  
  9. Me.SetTextBoxValues(GetTextBoxValues)
  10. If values(TextBoxIndices.txtFirstName) <> "" Then
  11.  
  12. Try
  13. Dim strFirstName As String = _
  14. values(TextBoxIndices.txtFirstName)
  15.  
  16. If strFirstName <> "" Then
  17. record.strFirstName = values(TextBoxIndices.txtFirstName)
  18. record.strLastName = values(TextBoxIndices.txtLastName)
  19. record.strCourseName = values(ComboBoxIndices.cboCourseName)
  20. record.strStudentId = values(TextBoxIndices.txtStudentId)
  21. record.strGrade = values(ComboBoxIndices.cboGrade)
  22.  
  23. fileWriter.WriteLine( _
  24. record.strFirstName.ToString & "," & record.strLastName.ToString & "," & _
  25. record.strStudentId.ToString & "," & record.strCourseName.ToString & "," & _
  26. record.strGrade.ToString)
  27.  
  28.  
  29. Else
  30. MessageBox.Show("Invalid First Name", "Error", _
  31. MessageBoxButtons.OK, MessageBoxIcon.Error)
  32. End If
  33.  
  34. Catch ex As IOException
  35. MessageBox.Show("Error Writing to File", "Error", _
  36. MessageBoxButtons.OK, MessageBoxIcon.Error)
  37.  
  38. Catch ex As FormatException
  39. MessageBox.Show("Invalid Format", "Error", _
  40. MessageBoxButtons.OK, MessageBoxIcon.Error)
  41.  
  42. End Try
  43. End If
  44.  
  45. Me.SetTextBoxValues(GetTextBoxValues)
  46. Me.ClearFormDataEntryBoxes()
  47.  
  48. End Sub
  49. (Rate)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
robee31 is offline Offline
2 posts
since Nov 2008
Nov 12th, 2008
0

Re: Null Reference Exception Unhandled

hi
first set the breakpoint to starting line of function and then u can no eaasily somwhere its not set the value that s y this above error and use try-catch block its useful to findout that error
Last edited by Renukavani; Nov 12th, 2008 at 12:33 am.
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Need advice on sockets/threads
Next Thread in VB.NET Forum Timeline: OOLEDB Connection(vb.net & Access)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC