Section 6.4. Code File Contents


6.4. Code File Contents

Visual Basic applications include one or more source code files and possibly some other miscellaneous files (such as ".resx" resource files). These files contain all of the types (classes, structures, enumerations, etc.) of your application. Just as in Visual Basic 6, there is a small declarations section available at the start of each code file, followed by the actual code.

6.4.1. Declarations Section

The declarations section of a code file includes statements that set up the environment for all the code in that file. This section may include the various Option statements (Option Compare, Option Explicit, Option Strict) and Imports statements that make possible terse class references in the code file. Application-specific and module-specific attributes are defined here as well.

Unlike with VB 6, no global variables, constants, or Declare statements appear in the declarations section.

6.4.2. Namespaces

All types must appear in namespaces in .NET. By default, all of the code in your application appears in a top-level namespace that has the same name as your project's name. You can override this default in the project property settings or identify a specific namespace for your types by using the Namespace statement. Namespaces can be nested.

     Namespace Level1        Namespace Level2           ' ---- Perhaps put some code here.        End Namespace        ' ----- Or even here.     End Namespace 

All namespaces are public.

New in 2005. The new Global keyword provides a way to resolve conflicts in namespace usage. For instance, if your application included a namespace named MyCompany.System, and you used the Imports MyCompany statement in your code file, would a reference to "System" mean the .NET-supplied System namespace or the MyCompany.System namespace? The Global keyword solves the problem. To access the .NET-supplied System namespace, reference Global.System, which removes any ambiguity.

6.4.3. Types

Most of your application is defined through types : the classes, structures, enumerations, interfaces, and so on, of your application. Many types can be nested.

     Public Class ClassDepth1        Public Class ClassDepth2           ' ----- Add code here.        End Class        ' ----- And here, too.     End Class 

Types contain members, mainly the methods, properties, events, and fields of your classes and structures. Members cannot be nested, although members with the same name may appear within different nested types. For instance, if Class A contains Class B, both A and B may include a procedure named ProcessData without conflict.




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net