that does something is like a folder with stuff in it。 When you are creating the filing system; you don’t care about the contents of the folder。 And when you fill the folder; you generally don’t care about the filing system。 Modules; classes; namespaces; and methods are all concepts used to organize source code。 A method is filled with source code and does something like add numbers or create a textual string。 One of the most mon things that you will do when filling a method with source code is reference other pieces of organized source code。 Think of referencing as putting a sticky note in a folder with the text; “Please also look in folder B。” Following is a piece of source code that is 100% organizational and does nothing。 Namespace MyMainTypes Public Class AType Public Shared Sub DoSomething() End Sub End Class End Namespace Module AnotherType Public Function DoSomething() As Integer End Function End Module The source code has three levels of organization。 A namespace (MyMainTypes in the example) encapsulates types like classes (AType in the example)。 Classes and modules (like AnotherType in the example) encapsulate methods (DoSomething() in the example) or properties。 Within a namespace; all types must be unique。 You can have two types with the same identifier in different namespaces。 Within a type; you cannot have identical identifiers with identical parameters。 (This will be clearer as you learn more about Visual Basic in the uping chapters。) Visual Basic has the additional rule that classes and modules (like AType and AnotherType) are in the namespace of the Visual Basic project。 That namespace is not explicitly defined; but it is identified by the project; as shown in Figure 2…6。 In Figure 2…6; the Root Namespace text box shows the root namespace of all types in a Visual Basic project。 So if both AType and AnotherType were part of the project; the full…length identifiers would be Calculator。MyMainTypes。AType and Calculator。AnotherType。 …………………………………………………………Page 54…………………………………………………………… 32 CH AP T E R 2 ■ L E A R N IN G AB OU T 。 N E T N U M B E R A N D V A L U E T Y P E S Figure 2…6。 Default root namespace of project Following is the same organizational code with some source code added to do something (shown in boldface)。 Namespace MyMainTypes Public Class AType Public Shared Sub DoSomething() End Sub End Class End Namespace Module AnotherType Public Function DoSomething() as Integer MyMainTypes。AType。DoSomething() End Function End Module In the bolded code; there is a reference to another namespace; type; and method with a pair of parentheses。 This makes a method call on a shared class and shared method。 It says that the implementation of the method is the calling of another method。 …………………………………………………………Page 55…………………………………………………………… CH A PT E R 2 ■ L E A R N I N G A B OU T 。 N E T N U M B E R AN D V A L U E T Y P E S 33 Notice how the other method is referenced using both namespace and type identifiers。 Also notice how there is no reference to the Calculator namespace。 This is not necessary because; from the perspective of AnotherType; Calculator is implied。 This is how all types and methods are always referenced。 A namespace identifier is necessary only if the type (for example; class) is not defined in the current namespace。 If you have namespaces with long names; this referencing can get tedious。 As an alterna tive; you can add an Imports statement to reference the namespace; similar to the following。 Imports Calculator。MyMainTypes Module AnotherType Public Function DoSomething() as Integer AType。DoSomething() End Function End Module The Imports statement says that if the code references any types that are not defined locally; look in this namespace (Calculator。MyMainTypes in the example) to find the type。 When using the Imports statement; you need to specify the full namespace of Calculator。MyMainTypes。 Note that if you use two namespaces that have identically named types; you will get a piler failure; because the piler won’t know which type to reference。 This covers the absolute basics of writing some code; and we are ready to use Visual Basic to do something。 Writing the Add() Method We’ll write the code to add two numbers。 To begin; create a new project in Visual Basic: 1。 Open Visual Basic Express。 (If Visual Basic Express is open; choose File Close Project to ensure you have a clean slate。) 2。 Click File New Project or choose Create: Project from the Start Page tab。 3。 Choose Class Library; name it Calculator; and click OK。 4。 Rename Class1。vb to Operations。vb。 5。 Save the solution。 We can now write the Add() method。 Add the bolded code to the Operations。vb file。 Public Class Operations Public Shared Function Add(ByVal number1 As Integer; ByVal number2 As _ Integer) As Integer Return number1 + number2 End Function End Class This simple code actually has many different pieces that fit together。 The type Operations is implied to be in the namespace Calculator because the default root namespace is the same as the project。 Defined within Operations is a method that is both Public and Shared。 Using the …………………………………………………………Page 56…………………………………………………………… 34 CH AP T E R 2 ■ L E A R N IN G AB OU T 。 N E T N U M B E R A N D V A L U E T Y P E