Results 1 to 5 of 5

Thread: Statement is Not a Valid Namespace

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2003
    Location
    Harrogate, UK
    Posts
    2

    Unhappy Statement is Not a Valid Namespace

    I am new to VB and VB.NET so be gentle.
    I am trying to declare 2 global variables in the general declaration section of my code as follows:

    Option Explicit On

    Public Const gcstrServer As String = "Server" & vbLf _
    Dim txtLogon As String = "MS Exchange Server"
    --------------------------------------------------------------------------

    This is giving me an error for both variable declarations:

    "Statement is not a valid namespace"

    What am I doing wrong? Any advice is much appreciated

    Many Thanks

    Mike Jones

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you cant put that outside a class definition. This is not VB6 where there was no visible definitions for class. When you add a new class to your app, the class definition is added for you..

    Public Class Class1
    ' Code in here


    End Class
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2003
    Location
    Harrogate, UK
    Posts
    2
    Cheers Cander.
    I am getting to grips with this slowly. I am originally a Java programmer trying to make the leap accross. Does that mean that if any variables that are declared in a public class are globally accessible making the general decs bit redundant.

    Mike

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    They are only accessible to the class. But if you make the variables public, then you can access them outside the class using standard object oriented programming.

    classname.variablename

    VB.NET, except for syntax, follows much the same rules and skills as java does, so just keep that in mind.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    To extend your knowledge , you can do this :
    VB Code:
    1. Namespace mYnSpace
    2.  
    3. Public Enum a
    4.         i = 0
    5.         x = 2
    6.     End Enum
    7.  
    8. Public Delegate Sub Dlg()
    9.  
    10. Public Class Class1
    11.  
    12. 'CODE HERE
    13.  
    14. End Class
    15.  
    16. End Namespace

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width