VB errors that I am not sure how to fix


  • Error    1    Statement is not valid in a namespace.    C:\New Folder\WeatherReport.vb    1    1    WindowsApplication1

    Error    2    'Class' statement must end with a matching 'End Class'.    C:\New Folder\WeatherReport.vb    5    1    WindowsApplication1

    These errors are new to me, especially, since I am new to VB .net. I cant figure out how to correct the errors and the help part of VB does not help either. Can anyone tell me how to fix these errors?

    Sunday, July 20, 2008 1:59 AM


  • You can usually copy/paste the error you're receiving in the search bar at the top of these forums, or at the MSDN site ( and the results should point you in the right direction. Otherwise a web search should too. Also the VB.NET Language forum for further help is located here:

    Your 1st error is likely being caused by having an invalid statement somewhere between your Namespace declaration and your Class declaration. Try moving those statements right after your Class declaration. From

    The statement cannot appear at the level of a namespace. The only declarations allowed at namespace level are module, interface, class, delegate, enumeration, and structure declarations.

    Error ID: BC30001

    To correct this error

    • Move the statement to a location within a module, class, interface, structure, enumeration, or delegate definition.

    So for example if you have something like:

    Namespace test 
    Dim myString As String  
    Public Class myClass 

    Change it to:

    Namespace test 
    Public Class myClass 
    ' Moved statement inside valid location 
    Dim myString As String  
    'More code here...

    Your 2nd error should be fixed easily by adding "End Class" to the end of your class:

    Public Class myClass 
    'More code here...
    'Must end with a matching End Class 
    End Class 

    Document my code? Why do you think it's called "code"?
    • Edited by Ahmad Mageed Sunday, July 20, 2008 5:08 AM added search info
    • Marked as answer by Zhi-Xin Ye Thursday, July 24, 2008 3:00 AM
    Sunday, July 20, 2008 5:04 AM