Vb.net 编译时未处理Get InvalidoOperationException

Vb.net 编译时未处理Get InvalidoOperationException,vb.net,Vb.net,在对文本字段进行验证之前,一切都很顺利 为什么它不能编译 创建表单时出错。 有关详细信息,请参阅Exception.InnerException 细节。错误是:外部的 组件已引发异常 资料来源: Public Class frmAddStudent Dim aryData(6) As String Public Shared newStudentRecord As String Private Sub btnCancel_Click(ByVal sender As Sy

在对文本字段进行验证之前,一切都很顺利

为什么它不能编译

创建表单时出错。 有关详细信息,请参阅Exception.InnerException 细节。错误是:外部的 组件已引发异常

资料来源:

Public Class frmAddStudent
    Dim aryData(6) As String
    Public Shared newStudentRecord As String

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = DialogResult.Cancel
    End Sub

    Private Sub btnAddStudent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddStudent.Click
        'place all the student field data into the array of elements
        aryData(0) = txtFirstName.Text
        aryData(1) = txtLastName.Text
        aryData(2) = txtMajor.Text
        aryData(3) = txtPhone.Text
        aryData(4) = txtEmail.Text
        aryData(5) = txtGPA.Text

        'join the array elements and place the result into a string variable
        newStudentRecord = Join(aryData, " ")

        'create a link between the form and the file with streamwriter and write to the text file
        If System.IO.File.Exists(frmMain.FILE_NAME) = True Then
            Dim objWriter As New System.IO.StreamWriter(frmMain.FILE_NAME, True)
            objWriter.WriteLine(newStudentRecord)
            objWriter.Close()
        End If
        Me.DialogResult = DialogResult.OK
    End Sub

    Private Sub txtFirstName_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtFirstName.Validating
        If txtFirstName.Text.Contains(" ") Or txtFirstName.Text.Length = 0 Or Not System.Text.RegularExpressions.Regex.IsMatch(txtFirstName.Text, "[a-z|A-Z]+$") Then
            ErrorProvider1.SetError(txtFirstName, "First Name can't contain spaces or be of zero length and must consist of only letters")
            e.Cancel = True
        Else
            ErrorProvider1.SetError(txtFirstName, "")
        End If
    End Sub

    Private Sub frmAddStudent_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ErrorProvider1.BlinkStyle = ErrorBlinkStyle.NeverBlink
    End Sub

    Private Sub txtLastName_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtLastName.Validating
        If txtLastName.Text.Contains(" ") Or txtLastName.Text.Length = 0 Or Not System.Text.RegularExpressions.Regex.IsMatch(txtLastName.Text, "[a-z|A-Z]+$") Then
            ErrorProvider1.SetError(txtLastName, "Last Name can't contain spaces or be of zero length and must consist of only letters")
            e.Cancel = True
        Else
            ErrorProvider1.SetError(txtLastName, "")
        End If
    End Sub

    Private Sub txtMajor_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMajor.Validating
        If txtMajor.Text.Length > 0 Then
            If Not System.Text.RegularExpressions.Regex.IsMatch(Strings.Left(txtMajor.Text, 1), "[a-z|A-Z]+$") Then
                ErrorProvider1.SetError(txtMajor, "Major course code is incorrect")
            Else
                ErrorProvider1.SetError(txtMajor, "")
            End If
        Else
            ErrorProvider1.SetError(txtMajor, "Major cant' be zero length")
        End If
    End Sub
End Class

编辑:这里还有一个指向该问题的PrtSc的链接:

看起来您的ErrorProvider1正在引发异常。你能不能编辑这个问题,告诉我们关于错误的更多信息以及错误发生在哪一行?我想在帖子中添加一个链接,链接到问题的打印屏幕图像(就在线程的最底部,在所有源代码下)。至于关于错误的信息以及它发生在哪一行。。。它并没有说它是哪一行。这是一条糟糕的线。重新启动你的机器。有什么建议吗?这一直困扰着我一段时间。感觉很昏昏欲睡。