"语句在命名空间中无效"在按钮单击处理程序中

时间:2014-12-26 22:33:37

标签: vb.net

我的Private Sub btnDisplay点击事件程序告诉我(btnDisplay行上的蓝线错误消息):

  

"语句在命名空间中无效"`。

我已添加End SubEnd Class,但仍然收到相同的错误消息。

Public Class frmMain

   Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    Me.Close()

   End Sub
End Class

Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click

    ' displays D's 3 comments

    Dim intChoice As Integer
    Integer.TryParse(txtChoice.Text, intChoice)


    If intChoice = 1 Then
        lblComment.Text = "Not Exactly"
    Else
        If intChoice = 2 Then
            lblComment.Text = "No, Were You Listening?"
        Else
            If intChoice = 3 Then
                lblComment.Text = "This Is Close"
            Else
                lblComment.Text = "N/A"
            End If
        End If
    End If
End Sub

1 个答案:

答案 0 :(得分:0)

嗯,这正是错误消息所说的 - 像Private Sub这样的方法声明不是命名空间内的有效语句(读取:在类/模块之外)。试试这个:

Public Class frmMain

  Private Sub btnExit_Click(sender As Object, e As EventArgs) _
                                                            Handles btnExit.Click
    Me.Close()
  End Sub

  Private Sub btnDisplay_Click(sender As Object, e As EventArgs) _
                                                         Handles btnDisplay.Click
    'your code goes here
  End Sub

End Class