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

fileWriter.WriteLine( _
                    record.strFirstName & "," & record.strLastName & "," & _
                    record.strStudentId & "," & record.strCourseName & "," & _
                    record.strGrade)

hi
send ur ful code then v can help u

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.

Private Sub btnEnter_Click(ByVal sender As System.Object, _
                               ByVal e As System.EventArgs) _
                               Handles btnEnter.Click

        Dim values As String() = GetTextBoxValues()

        Dim record As New GradeBookDataCollector()

        Me.SetTextBoxValues(GetTextBoxValues)
        If values(TextBoxIndices.txtFirstName) <> "" Then

            Try
                Dim strFirstName As String = _
                    values(TextBoxIndices.txtFirstName)

                If strFirstName <> "" Then
                    record.strFirstName = values(TextBoxIndices.txtFirstName)
                    record.strLastName = values(TextBoxIndices.txtLastName)
                    record.strCourseName = values(ComboBoxIndices.cboCourseName)
                    record.strStudentId = values(TextBoxIndices.txtStudentId)
                    record.strGrade = values(ComboBoxIndices.cboGrade)

                    fileWriter.WriteLine( _
                    record.strFirstName.ToString & "," & record.strLastName.ToString & "," & _
                    record.strStudentId.ToString & "," & record.strCourseName.ToString & "," & _
                    record.strGrade.ToString)


                Else
                    MessageBox.Show("Invalid First Name", "Error", _
                    MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If

            Catch ex As IOException
                MessageBox.Show("Error Writing to File", "Error", _
                MessageBoxButtons.OK, MessageBoxIcon.Error)

            Catch ex As FormatException
                MessageBox.Show("Invalid Format", "Error", _
               MessageBoxButtons.OK, MessageBoxIcon.Error)

            End Try
        End If

        Me.SetTextBoxValues(GetTextBoxValues)
        Me.ClearFormDataEntryBoxes()

    End Sub 
 (Rate)

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

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.