Classes, Structures, and Modules


Modules, classes, and structures create their own name contexts that are similar in some ways to namespaces. For example, a class can contain the definition of another class and a structure can contain the definition of another structure, as shown in the following code:

  Public Class Class1     Public Class Class2         ...     End Class End Class Public Structure Struct1     Public Name As String     Public Structure Struct2         Public Name As String     End Structure End Structure  

You can access public module members and shared class or structure members using a fully qualified syntax similar to the one used by namespaces. For example, the following code creates the GlobalValues module and defines the public variable MaxJobs within it. Later, the program can set MaxJobs using its fully qualified name.

  Module GlobalValues     Public MaxJobs As Integer     ... End Module ... MyApplication.GlobalValues.MaxJobs = 100  

Although these cases look very similar to namespaces, they really are not. One big difference is that you cannot use a Namespace statement inside a class, structure, or module.

IntelliSense gives another clue that Visual Basic treats classes, structures, and modules differently from namespaces. The IntelliSense popup shown in Figure 17-4 displays curly braces {} next to the FinanceStuff and JobClasses namespaces, but it displays different icons for the classes Employer and Form1, and the module Module1. When you select a namespace, IntelliSense also displays a tooltip (on the right in Figure 17-4) giving the namespace’s name.

image from book
Figure 17-4: IntelliSense displays curly braces {} to the left of namespaces such as FinanceStuff and JobClasses.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

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